Public Group

# what to do now?

This topic is 3391 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts


#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;

int Diceroll();
void Introscreen();
void Tryagain();
void Win();
int Totalbears;
int Dicenumber;
int Totalcorrect;
string PLAYAGAIN;
string NAME;
bool PLAY = true;

int main()
{
srand((unsigned)time(NULL));

Introscreen();

string PLAYAGAIN = "yes";

while (PLAYAGAIN == "yes")

while(PLAY)
{

Totalcorrect = 0;

for (int iCOUNT=1; iCOUNT<11; iCOUNT++)
{

{
Win();
}

Diceroll();

cout<<"How many polar bears do you see around the ice holes?"<<endl;

{
cout<<"Correct! =D"<<endl;
Totalcorrect++;
}
else
{
cout<<"Incorrect! The right answer was: "<<Totalbears<<endl;
}
system("pause");

Tryagain();
}
}
return 0;
}

void LOSE (string NAME)

{
//the losing screen
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<< endl;
cout<<"!                                      !"<<endl;
cout<<"!        Sorry,                        !"<<endl;
cout<<"!                 You Lose!            !"<<endl;
cout<<"!                                      !"<<endl;
cout<<"!                                      !"<<endl;
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;
cout<<endl;

cout<<"SORRY "<<NAME<< " YOU LOST"<<endl<<endl;
cout<<"BETTER LUCK NEXT TIME"<<endl;
}
//the intoduction screen
void Introscreen()
{
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;
cout<<"!                                      !"<<endl;
cout<<"!                                      !"<<endl;
cout<<"!             Ice and Dice             !"<<endl;
cout<<"!                                      !"<<endl;
cout<<"!                                      !"<<endl;
cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;
cout<<endl;

cout<<"Game details:"<<endl;
cout<<"The name is in the game, and the game is in the name."<<endl;
cout<<"and the name of the game is Polar Bears Around An Ice Hole."<<endl;
cout<<"Some people call this Petals Around A Rose."<<endl<<endl;
cout<<endl;
cin>>NAME;
}

int Diceroll()
{
Totalbears = 0;

for (int numRoll = 1; numRoll<4; numRoll++)
{
Dicenumber=1+rand()%6;

switch(Dicenumber)
{
case 1:
{
cout<<"*******"<<endl;
cout<<"*     *"<<endl;
cout<<"*  O  *"<<endl;
cout<<"*     *"<<endl;
cout<<"*******"<<endl;
Totalbears = Totalbears+0;
break;
}

case 2:
{
cout<<"********"<<endl;
cout<<"*    O *"<<endl;
cout<<"*      *"<<endl;
cout<<"* O    *"<<endl;
cout<<"********"<<endl;
Totalbears = Totalbears+0;
break;
}

case 3:
{
cout<<"*******"<<endl;
cout<<"*  O  *"<<endl;
cout<<"*  O  *"<<endl;
cout<<"*  O  *"<<endl;
cout<<"*******"<<endl;
Totalbears = Totalbears+2;
break;
}

case 4:
{
cout<<"*********"<<endl;
cout<<"*  O O  *"<<endl;
cout<<"*       *"<<endl;
cout<<"*  O O  *"<<endl;
cout<<"*********"<<endl;
Totalbears = Totalbears+0;
break;
}

case 5:
{
cout<<"*********"<<endl;
cout<<"* O   O *"<<endl;
cout<<"*   O   *"<<endl;
cout<<"* O   O *"<<endl;
cout<<"*********"<<endl;
Totalbears = Totalbears+4;
break;
}

case 6:
{
cout<<"********"<<endl;
cout<<"* O  O *"<<endl;
cout<<"* O  O *"<<endl;
cout<<"* O  O *"<<endl;
cout<<"********"<<endl;
Totalbears = Totalbears+0;
break;
}

default:
break;
}//end of switch
}
return 0;
}
void Win ()
{
cout<<"Congratulations, "<<NAME<<", You have won! =D"<<endl;
}
void Tryagain()
{
cout<<"Want to play again? (yes or no)"<<endl;
cin>>PLAYAGAIN;

if (PLAYAGAIN == "no")
{
PLAY = false;
cout<<"Okay, Thanks for playing. Bye"<<endl;
}
string PLAYAGAIN = "no";
{
while (PLAYAGAIN == "no")

system("PAUSE");
}
if (PLAYAGAIN == "yes")
{
PLAY = true;
cout<<"Okay!"<<endl;
}
}


[Edited by - Lorraine_B on May 2, 2009 2:38:13 PM]

##### Share on other sites
Experience tells that a person loses a lot of potential help by posting a big lump of unformatted code - You should use the [ source ][ /source ] tags which will colourise keywords and preserve code indents.

##### Share on other sites
the part that im sure is where i have to make changes is

im just like totaly stuck on where to put anything at, i have tried a bunch of things last night and everytime i changed something it just said i had a bunch of errors, so i need to be like taught where and why. nothing i have ever read said like you put this code under this line for this reason lol.

int main(){		srand((unsigned)time(NULL));		Introscreen();		string PLAYAGAIN = "yes";		while (PLAYAGAIN == "yes")		while(PLAY)		{				Totalcorrect = 0;				for (int iCOUNT=1; iCOUNT<11; iCOUNT++)				{						if (Useranswer==3)						{								Win();						}						Diceroll();						cout<<"How many polar bears do you see around the ice holes?"<<endl;						cin>>Useranswer;						if (Useranswer == Totalbears)						{ 								cout<<"Correct! =D"<<endl;								Totalcorrect++;						}						else						{								cout<<"Incorrect! The right answer was: "<<Totalbears<<endl;						}						system("pause");						Tryagain();				}		}		return 0;		}

[Edited by - Lorraine_B on May 2, 2009 2:01:06 PM]

##### Share on other sites
Quote:
 Original post by Lorraine_Bsee it makes it all scrabled up looking when i use the source and /source things
There are two reasons for that, one is that you use actual tabs for indents as opposed to, say, 4 spaces; the other is that if you post code in these forums without tags around then, annoyingly, things get regex'd into oblivion, if you do a fresh paste of your code back in between the tags then it'll fix that one [smile].

##### Share on other sites
Well its quite simple :), I've done all the hard work for you, now make sure you learn from it! If possible :) hehe:

#include <iostream>#include <string>#include <cstdlib>#include <ctime>using namespace std;int Diceroll();void Introscreen();void Tryagain();void LOSE(string name);void Win();		int Totalbears;		int Dicenumber;		int Useranswer;		int Totalcorrect = 0;		string PLAYAGAIN;		string NAME;		bool PLAY = true;int main(){		srand((unsigned)time(NULL));		Introscreen();		string PLAYAGAIN = "yes";		while (PLAYAGAIN == "yes")		while(PLAY)		{				for (int iCOUNT=1; iCOUNT<11; iCOUNT++)				{						Diceroll();						cout<<"How many polar bears do you see around the ice holes?"<<endl;						cin>>Useranswer;						if (Useranswer == Totalbears)						{ 								cout<<"Correct! =D"<<endl;								Totalcorrect++;						}						else						{								cout<<"Incorrect! The right answer was: "<<Totalbears<<endl;						}						system("pause");                        if(iCOUNT == 10)						{                         if(Totalcorrect == 3) Win();						 else LOSE(NAME);						 Totalcorrect = 0;						 Tryagain();						}						if(PLAY == false) return 0;				}		}		return 0;		}void LOSE (string NAME){		//the losing screen		cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<< endl;		cout<<"!                                      !"<<endl;		cout<<"!        Sorry,                        !"<<endl;		cout<<"!                 You Lose!            !"<<endl;		cout<<"!                                      !"<<endl;		cout<<"!                                      !"<<endl;		cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;		cout<<endl;		cout<<"SORRY "<<NAME<< " YOU LOST"<<endl<<endl;		cout<<"BETTER LUCK NEXT TIME"<<endl;}		//the intoduction screenvoid Introscreen(){		cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl;		cout<<"!                                      !"<<endl;		cout<<"!                                      !"<<endl;		cout<<"!             Ice and Dice             !"<<endl;		cout<<"!                                      !"<<endl;		cout<<"!                                      !"<<endl;		cout<<"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%"<<endl<<endl;		cout<<endl;		cout<<"Game details:"<<endl;		cout<<"The name is in the game, and the game is in the name."<<endl;		cout<<"and the name of the game is Polar Bears Around An Ice Hole."<<endl;		cout<<"Some people call this Petals Around A Rose."<<endl<<endl;		cout<<endl;		cout<<"Wish to play? Please enter your name here:"<<endl;		cin>>NAME;}int Diceroll(){		Totalbears = 0;		for (int numRoll = 1; numRoll<4; numRoll++)		{				Dicenumber=1+rand()%6;				switch(Dicenumber)				{						case 1:						{								cout<<"*******"<<endl;								cout<<"*     *"<<endl;								cout<<"*  O  *"<<endl;								cout<<"*     *"<<endl;								cout<<"*******"<<endl;								Totalbears = Totalbears+0;								break;						}						case 2:						{								cout<<"********"<<endl;								cout<<"*    O *"<<endl;								cout<<"*      *"<<endl;								cout<<"* O    *"<<endl;								cout<<"********"<<endl;								Totalbears = Totalbears+0;								break;						}						case 3:						{								cout<<"*******"<<endl;								cout<<"*  O  *"<<endl;								cout<<"*  O  *"<<endl;								cout<<"*  O  *"<<endl;								cout<<"*******"<<endl;								Totalbears = Totalbears+2;								break;						}						case 4:						{								cout<<"*********"<<endl;								cout<<"*  O O  *"<<endl;								cout<<"*       *"<<endl;								cout<<"*  O O  *"<<endl;								cout<<"*********"<<endl;								Totalbears = Totalbears+0;								break;						}						case 5:						{								cout<<"*********"<<endl;								cout<<"* O   O *"<<endl;								cout<<"*   O   *"<<endl;								cout<<"* O   O *"<<endl;								cout<<"*********"<<endl;								Totalbears = Totalbears+4;								break;						}						case 6:						{								cout<<"********"<<endl;								cout<<"* O  O *"<<endl;								cout<<"* O  O *"<<endl;								cout<<"* O  O *"<<endl;								cout<<"********"<<endl;								Totalbears = Totalbears+0;								break;						}						default:						break;				}//end of switch		}		return 0;}void Win (){		cout<<"Congratulations, "<<NAME<<", You have won! =D"<<endl;}void Tryagain(){		cout<<"Want to play again? (yes or no)"<<endl;		cin>>PLAYAGAIN;		if (PLAYAGAIN == "no")		{		PLAY = false;		cout<<"Okay, Thanks for playing. Bye"<<endl;		}		if (PLAYAGAIN == "yes")		{		PLAY = true;		cout<<"Okay!"<<endl;		}}

I got very confused because there were many things wrong with the code and I couldn't wrap my head around it. Well it wasn't exactly wrong... but just should have not been done like that. I'm not sure if I got what you needed done but there it is.

:D.

##### Share on other sites
I don't think the game's logic is completely defined yet. If I answer correctly on the first three attempts do I win straight away or do I have to sit through 7 more questions? If I answer incorrectly 8 times, then I can't possibly win, do I have to answer the remaining questins before being told I've lost?

##### Share on other sites
Well I just did what Lorraine asked me to :). And that was to be able to quit if the user types "no" when asked whether or not to continue and to make sure that the user goes through 10 rounds and then be told whether he or she has won (which would be three correct answers), I didn't do anything else.

##### Share on other sites
Quote:
 Original post by VirtualProgrammerWell I just did what Lorraine asked me to :).
Yeah, I can see how you've interpreted the task based on your code. I'd love to make a complete and detailed post on how I would have written this program but, unfortunately, I'm really too swamped with work to even consider it without knowing exactly what Lorraine_B wants - and even then I may simple be too busy to get round to it. It is possible Zahlman will step in and do it, but looking at his recent posting history he might be otherwise preoccupied too; perhaps if I dare someone to...?

Not bad for two weeks though Lorraine_B [smile]

##### Share on other sites
Quote:
Original post by dmatter
Quote:
 Original post by VirtualProgrammerWell I just did what Lorraine asked me to :).
Yeah, I can see how you've interpreted the task based on your code. I'd love to make a complete and detailed post on how I would have written this program but, unfortunately, I'm really too swamped with work to even consider it without knowing exactly what Lorraine_B wants - and even then I may simple be too busy to get round to it. It is possible Zahlman will step in and do it, but looking at his recent posting history he might be otherwise preoccupied too; perhaps if I dare someone to...?

Not bad for two weeks though Lorraine_B [smile]

The only problem is that this program, from evidence in earlier posts, is homework, so we can't show how we would write it. I would have already done so if not for this fact.

##### Share on other sites
Quote:
 Original post by rip-offThe only problem is that this program, from evidence in earlier posts, is homework, so we can't show how we would write it. I would have already done so if not for this fact.
Ah, thanks for sharing that; it looks like you've been helping a lot with this already.

1. 1
2. 2
frob
16
3. 3
4. 4
5. 5

• 13
• 13
• 61
• 14
• 15
• ### Forum Statistics

• Total Topics
632125
• Total Posts
3004252

×