Jump to content
  • Advertisement
Sign in to follow this  
Lorraine_B

what to do now?

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

please help me im really new to C++ and sooo confused. ill get right to it, im trying to make this game, i have almost all of it done except a few minor problems. so far it will open, show intro screen, ask there name, they type in there name, then it shows 3 dice and asks them how many polar bears are round the holes..then if they gues right it says correct if they gues wrong it says incorrect, then it just asks if they want to play again. and thats all it will do. how ever, i need it to let them have 10 guesses , if they get 3 guesses correct then they win the game (shows win screen) then to ask if they like to play again. orr if they guess 10 times and they dont get 3 correct, it needs to show the loose screen, and then ask if they wana play again. ALSO, how do i make the program close after they say no they dont want to play again?(after it says bye ofcourse) ok now i have some idea of what i need to do, im thinking i need to add int guesses; bool done; done= false; done= true; while ((guesses < 10) && (!done)) however im not sure where i need to add them, do i add them on the int main section? please help im super new to this stuff, like i only been doing it for a couple weeks. heres my code:
 
#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>

using namespace std;


int Diceroll();
void Introscreen();
void Tryagain();
void Win();
		int Totalbears;
		int Dicenumber;
		int Useranswer;
		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++)
				{

						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;
		}


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;
		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;
		}
		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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Lorraine_B
see 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 this post


Link to post
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 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;
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by VirtualProgrammer
Well 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 this post


Link to post
Share on other sites
Quote:
Original post by dmatter
Quote:
Original post by VirtualProgrammer
Well 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 this post


Link to post
Share on other sites
Quote:
Original post by rip-off
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.
Ah, thanks for sharing that; it looks like you've been helping a lot with this already.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!