That does help because i now know that its not my if statement thats messed up, its the rest of my code, so all the help is appriciated on this one. its a baby code im tryin to right up real fast.
#include <iostream>
#include <cstdlib>
#include <cstdio>
usingnamespace std;
int main(){
int answer1;
char name[20];
int hp=100;
int exp=1000;
int xparray[10];
int level=1;
cout << "Name" << endl;
cin >> name;
cout << "Welcome!"<< endl;
cout << "HP:";
cout << hp << endl;
cout << "Exp:";
cout << exp << endl;
cout << "This is the world of the programmer of this game. Unknown to even me!" << endl;
cout << "In this game, you as the begginer must answer general knowledge questions to level, and meet your maker!" << endl;
cout << "Right answers yield experience!! Play wisely...." << endl;
cout << "Question 1:";
cout << "In 1492 Columbus sailed the ocean ____" << endl;
cout << "1.Blue" << endl;
cout << "2.Yellow" << endl;
cout << "3.Purple" << endl;
cout << "4.I never went to school....ever!" << endl;
cin >> answer1;
if (answer1==1){
exp=500+4500;
cout << "Gained 500 exp!" << endl;
cout << exp << endl;
}else{
cout << "Incorrect!"<< endl;
};
// Experience Array
xparray[1]=5000;
xparray[2]=10000;
xparray[3]=25000;
xparray[4]=100000;
xparray[5]=275000;
xparray[6]=400000;
xparray[7]=550000;
for (int exp=5000; level < 1; level++) {
cout << "You have reached level 2!" << endl;
cout << level;
};
for (int exp=10000; level < 2; level++) {
cout << "You have reached level 3!" << endl;
cout << level;
};
for (int exp=25000; level < 3; level++) {
cout << "You have reached level 4!" << endl;
cout << level;
};
for (int exp=100000; level < 4; level++) {
cout << "You have reached level 5!" << endl;
cout << level;
};
system("pause");
return 0;
};
The array at this point and time im still wondering if i want to use so im trying different methods. this would be the first(the if statement i mean) and then i will try the array, see if thats an easier approach.
So did i forget a ';' or somethin.....from wat i can tell the code jus contiues to execute the exp=500+100 but not the cout's. so when i run it it comes out
Incorrect!
1500(curent exp after calc which shouldnt happen)
and i did a check on my for statements and thats screwy to.
comes out the same ass above but jus replace 1000 with 4500 and no matter what it executes all for statements
Incorrect!
10500
2You have Reached lvl 2
3You have reached lvl 3
4You have reached lvl 4
But you can't include two variables in the same for loop unless it was like the x<y thing.
comes out the same ass above but jus replace 1000 with 4500 and no matter what it executes all for statements
Yes. I think it's for the reason I mentioned above, also because in the for loops, you have initialized the exp variable in all for loops after you have declared it with the rest of the variables in the beginning of the program. Remove the int inside the for loops, or ever remove the whole for loop, because I don't understand what a for loops is for over here? I mean you can do this code
if (answer1==1)
{
exp = exp +500; //Or exp+=500;
cout << "Gained 500 exp!" << endl;
cout << exp << endl;
}
else
cout << "Incorrect!"<< endl;
//...
//...
//Instead of the for loops do this for increasing levels.
if(exp>=1000)
{
level++;
cout << "You have reached level 2!" << endl;
}
//...
//...
//Do the same for all the other levels!!
there seems to be a lot of problems in the design I think. Especially with the for loops, The main reason we use loops/iterations are for repetitive tasks. I'm not sure what you're actually trying to do but it seems like you're trying to check the xp then say what level the user is at. So perhaps if statements are better suited for the job? And another note you don't need semi-colons after the for loops or if statements. The xp array wasn't used as well. :P
@hannad
But you can't include two variables in the same for loop unless it was like the x<y thing.
Actually you can use multiple variables in for loops, it's not really used much however.
example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
#include <limits>
int main()
{
for(int i = 0, j = 0; i < 10; i++, j+=2)
{
std::cout << "i : " << i << std::endl;
std::cout << "j : " << j << std::endl;
}
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
return 0;
}
Ok.
But you can't do as he did. You put two variables, put the increment for both and put the condition for both. He put the 1st variable. then the condition and increment was for another variable. That was what I was talking about. Thanks though.