For my introductory computer science programming class (C++) I need to make a co
ID: 672823 • Letter: F
Question
For my introductory computer science programming class (C++) I need to make a cootie game. We have to generate a random number from 1 to 7 and use it to pick which part to add.
The required logic is:
the instructions then say "
Add a loop around the logic above. The loop should end when the cootie is completed. To ensure that the loop around the whole program is correct and will eventually end; keep track of which parts have rolled already and how many of have been rolled. Create counters (int numLegs=0;) and increment (numLegs++) them when appropriate. (if (roll==1) {numBody=1;} )
With all that done, change the "if" so that you can only place pieces if the prerequisites are met. To add a leg, you need to have a body and the right dice roll. The code will look similar to:
if (roll == 6 && numBody == 1)
{
numLegs ++;
}
while (cootie isn't completed)
{
get the input
if (the input is a 1)
{
do the work to add a body
}
if (the input is a 2 and we can add a head)
{
do the work to add a head
}
(add the rest of the body parts)
}
Now make it so that you can replay games of cootie over and over again: (Include the number of rolls that were required to make the cootie)
[Play a game of cootie]
Your cootie was completed in 30 dice rolls.
Do you want to play again[y/n] y
[Play a game of cootie]
Your cootie was completed in 15 dice rolls.
Do you want to play again[y/n] y
[Play a game of cootie]
Your cootie was completed in 60 dice rolls.
Do you want to play again[y/n] n
Bye.
Please paste code that can be highlighted so I can learn from it. Thank you!
Maximum Number you may have. Also the number required if you already If the Roll is: You can add this Body Part have this partto finish the cootie 1 Body 2 Head 3 Antenna 4 Wings 5 Stinger 6 Legs 7 Eyes none Body Head Body Body Body Head 4Explanation / Answer
//Program:
//Note: Since it is a random number generator program, you have to wait
// till the program completed.
#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
int Roll,numOfTimesRolled=0;
int numBody=0, numHead=0, numAntennas=0, numWings=0, numStingers=0, numLegs=0, numEyes=0;
int finished=0;
string choice="y";
cout<<endl<<"[Play a game of cootie]";
cout<<endl<<"please wait. Assembling your cootie..............................";
while(choice.compare("y")==0 ||choice.compare("Y")==0)
{
while(finished==0)
{
Roll = rand()% 6+1;
if(Roll==1)
{
numBody=1;
}
else if(Roll==2 && numBody==1)
{
numHead=1;
}
else if(Roll==3 && numHead==1 && numAntennas<2)
{
numAntennas++;
}
else if(Roll==4 && numBody==1 && numWings<2)
{
numWings++;
}
else if(Roll==5 && numBody==1 &&numStingers<1)
{
numStingers++;
}
else if(Roll==6 && numBody==1 &&numLegs<4)
{
numLegs++;
}
else if(Roll==7 && numHead==1 &&numEyes<6)
{
numEyes++;
}
numOfTimesRolled++;
if(numBody==1 && numHead==1 && numAntennas==2 && numWings==2 && numStingers==1 &&numLegs==4 && numEyes==6)
finished=1;
}
cout<<endl<<"Your cootie was completed in "<<numOfTimesRolled<<"dice rolls.";
cout<<endl<<"Do you want to play again[y/n] ";
cin>>choice;
}
if(choice.compare("n")==0 )
cout<<endl<<"Bye";
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.