Sign in to follow this  
Lorraine_B

Help? Must return value? "error C4716

Recommended Posts

Lorraine_B    122
wow okay i just fixed it randomly wow im so happy.... but really bad news... after i open it it shows intro screen then asks the player there name, i type in a name, and then instead of switching over and going on through the game.... the intro screen pops right back up asking there name again.... please help?!? will someone thats real smart at C++ codes please look at this and point out and Explainnnnnn whats wrong. be aware im very new to this.
#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;

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<<"*  0  *"<<endl;
								cout<<"*     *"<<endl;
								cout<<"*******"<<endl;
								Totalbears = Totalbears+0;
								break;
						}

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

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

						case 4:
						{
								cout<<"*********"<<endl;
								cout<<"*  0 0  *"<<endl;
								cout<<"*       *"<<endl;
								cout<<"*  0 0  *"<<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<<"Bye"<<endl;
		}
		if (PLAYAGAIN == "yes")
		{
		PLAY = true;
		cout<<"Okay!"<<endl;
		}
}
int main()
{
		srand((unsigned)time(NULL));
		
		string PLAYAGAIN = "yes";

		while (PLAYAGAIN == "yes")
		
		Introscreen();

		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 1, 2009 11:03:00 PM]

Share this post


Link to post
Share on other sites
Lorraine_B    122
P.S. sorry its so big and spaced like that, when i copyd and pasted it.. it got all crazy spaced O_O

so dont worry on my screen in the program its not crazy like that lol

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by Lorraine_B
int function will return some information to whoever calls it

Exactly. In light of this, does it make any sense to make Introscreen() return an integer when you could simply mark it as not returning anything (using "void")? Especially when this value that is always zero and is ignored inside main().


Quote:

after i open it it shows intro screen then asks the player there name, i type in a name, and then instead of switching over and going on through the game.... the intro screen pops right back up asking there name again....

The answer to this is in the miscellaneous list of issues I made in my first response to your earlier thread.

Share this post


Link to post
Share on other sites
Daniel B    100
Functions need to return values, that is a rule in C++. The void datatype is for functions that do not have to return a value. While you still have a return statement, it returns (to put it simply) nothing (like an empty set in mathematics).

Share this post


Link to post
Share on other sites
Lorraine_B    122
okay do i put it like this:

void Introscreen()

?
if so... i get errors


cpp(104) : error C2562: 'Introscreen' : 'void' function returning a value


and a few others

Share this post


Link to post
Share on other sites
rip-off    10976
Remember that you have included a declaration "void function()" and a definition "void function() { ... }" for each function. If you change the return type in one, then you must change it in the other.

As an alternative to this, you could delete the declarations and move the definitions above main, as each definition can double as a declaration:

int Diceroll()
{
// code for Diceroll
}

int Introscreen()
{
// code for Introscreen
}

void Tryagain()
{
// code for Tryagain
}

void Win()
{
// code for Win
}

// variables

int main()
{
// main code
}

Share this post


Link to post
Share on other sites
Lorraine_B    122
wait what are the declarations?

well i moved the int main one to be last like you had it.

it works no errors....
but its stil doing the same thing, it wont get past the intro page, after it asks the persons name it just pops up again asking there name again

=(

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by Lorraine_B
wait what are the declarations?


A declaration is where you make a promise to the compiler. For example, your "Win" function. Its declaration is this:

void Win () ;

This means that Win is a function which takes no parameters and returns no values. You must declare a function before C++ will allow you to use it. Declarations most frequently used when breaking a larger program into multiple files, but occasionally must be used in the same file to resolve circular function calling (function A calls function B, and B also calls A).

The definition or implementation of a function is the actual body, like this:

void Win ()
{
cout<<"Congratulations, "<<NAME<<", You have won! =D"<<endl;
}



As I said before, a definition counts as a declaration aswell. So if there is no circular calling, then you can re-order the functions to avoid needing to declare them. This is usually a good thing, because declarations duplicate information in multiple locations, forcing you to make changes in all locations when you update your code.

This caused the error message you had earlier, you changed one of the definitions but forgot to update the declaration.

Share this post


Link to post
Share on other sites
Lorraine_B    122
okay i believe im following you on this, im pretty sure i understand

i updated the code up at the top so u can see what i have now, see? i moved the int main down to the bottom and changed the int intro to void intro


it woks, no errors but its stil doing same thing, wont get passed the introduciton page, it asks there name then pops up again asking there name again O_o

im reading around on google and everything at same time as talkin to you on here, cant find anything that helps =/

Share this post


Link to post
Share on other sites
Lorraine_B    122
okay i believe im following you on this, im pretty sure i understand

i updated the code up at the top so u can see what i have now, see? i moved the int main down to the bottom and changed the int intro to void intro


it woks, no errors but its stil doing same thing, wont get passed the introduciton page, it asks there name then pops up again asking there name again O_o

im reading around on google and everything at same time as talkin to you on here, cant find anything on google that helps =/

Share this post


Link to post
Share on other sites
rip-off    10976
Quote:
Original post by Lorraine_B
but its stil doing the same thing, it wont get past the intro page, after it asks the persons name it just pops up again asking there name again

Again, the solution to your problem is in your other thread. In my reply there I describe the exact symptoms you find when you run your program. I simply cannot make it any clearer without copying the quotation here.

Our continuing help is dependant on you showing that you can take on board advice already given.

Share this post


Link to post
Share on other sites
Lorraine_B    122
=0!!

im so sorry i totaly understand now like you meant since th intro screen was after the loop thingy it jsut kept going back to it

i totaly fixed that and it works now, but theres one small problem

how do i change it so that if they choose no they dont want to play again, for it to like close the program? (after it says bye)

Share this post


Link to post
Share on other sites
moff    100
In your for loop, make "iCOUNT<11" be "PLAY && iCOUNT<11" to be able to quit before the player runs out of retries.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this