What the heck? Why am I getting 2 errors?
I tryed and tryed to see what is wrong with this code, and it just doesn't seem to want to compile. I get these 2 errors:
Quote:
line 124 c:\dev-c_~1\mathfun.cpp parse error before `else'
line 142 c:\dev-c_~1\mathfun.cpp parse error at end of input
I was making this program for my little brother to help him with his times tables.
Here it is:
Code:
#include <iostream.h>
#include <stdlib.h>
#include <time.h>
#define MAX_RANGE 20
int main()
{
int answer;
int input;
int valuex;
int valuey;
int points;
int chance = 0;
start: // the beginnning labeled for a goto statement
for(int i = 0; i = 100; i++)
{
points++;
srand ( time (NULL) ); // Initialize random generator
valuex = rand()%MAX_RANGE+1; // Get random between 1 and MAX_RANGE
srand ( time (NULL) ); // Initialize random generator
valuey = rand()%MAX_RANGE+1; // Get random between 1 and MAX_RANGE
answer = valuex * valuey;
cout<<"What is"
<<valuex<<" x "
<<valuey<<"?";
cin>>input;
if(input != answer)
{
chance++;
cout<<"\n Sorry! That is wrong!\n"
<<valuex<<" x "<<valuey<<" =\n"
<<answer<<endl;
if(chance = 1)
{
cout<<"\n You have one more chance!\n"
<<"Press any key to continue. . .";
system("PAUSE > nul");
}
else if(chance = 2)
{
cout<<"\n This is your last chance... \n"
<<"Press any key to continue. . .";
system("PAUSE > nul");
}
else
{
system("CLS");
cout<<"GAME OVER!\n"
<<" You scored a total of "
<<points<<"points!";
if(points < 25)
{
cout<<"\n\n You are classed as a little kid.\n"
<<"Press any key to exit the game. . .\n";
system("PAUSE > nul");
return 0;
}
else if(points >= 25 &&(points < 50))
{
cout<<"\n\n You are classed as a 4th grader.\n"
<<"Press any key to exit the game. . .\n";
system("PAUSE > nul");
return 0;
}
else if(points >= 50 &&(points < 75))
{
cout<<"\n\n You are classed as an average person.\n"
<<"Press any key to exit the game. . .\n";
system("PAUSE > nul");
return 0;
}
else if(points >= 75 &&(points < 100))
{
cout<<"\n\n You are classed as a smarty pants.\n"
<<"Press any key to exit the game. . .\n";
system("PAUSE > nul");
return 0;
}
else
{
cout<<"\n\nWow! You only missed 2! Good job!\n\n"
<<"Press any key to exit the game. . .\n";
system("PAUSE > nul");
return 0;
}
} // end big if statement
else
cout<<"\nCorrect!\n\n";
}//end for loop
system("CLS");
cout<<"What the world?\n"
<<"Thats impossible!\n"
<<"How did you beat me?\n"
<<"\n\n You scored a total of "
<<points<<" points!\n"
<<"Thats amazing!!\n"
<<"Press any key to start the game over. . .";
system("PAUSE > nul");
goto start;
return 0;
}
I made it as neat as I could for its readablity. ;)
I think it has to do with the nested if statements within the for loop or something. Did you find any errors? If you did what was the error, and how do I fix it for my future programs?
Thank-you so much,
Best Regards,
Machewy