I built a program that asks for numbers and you have to do tasks with them (add one, double). The first "level" works fine, but the second one wont start. What have I done wrong?
This is the related code:
cout<< "The Rules of the Game are: enter the number equal to the number of times you have been asked to input a number. Start with 2\n";
do
{
cout << "Enter the number\n";
cin>> urnumber;
thenumber++;
}
while (urnumber==thenumber && thenumber<14);
if (urnumber!=thenumber)
{
cout<< "Game Over! You Lose";
cin.ignore ();
}
else if (thenumber>=15)
{
cout<< "Congratulations You've passed level 1! Now you have to enter the number double the number of times you've been asked! The current number is 15!";
int level2;
}
and this is the function level2:
int level2 ()
{
int doubler=15;
int rightanswer=30;
do
{
std::cout<< "Enter The Number";
std::cout;
rightanswer=thenumber+doubler;
thenumber++;
doubler++;
}
while (urnumber==rightanswer && rightanswer<50);
return 0;
}
It still doesnt work tho...
ill put in all the code
#include <iostream>
int go_to;
int thenumber=1;
int urnumber;
int level2 ()
{
int doubler=15;
int rightanswer=30;
do
{
std::cout<< "Enter The Number";
std::cout;
rightanswer=thenumber+doubler;
thenumber++;
doubler++;
}
while (urnumber==rightanswer && rightanswer<50);
return 0;
}
using namespace std;
int main ()
{
int doubler=15;
int rightanswer=30;
cout<< "The Rules of the Game are: enter the number equal to the number of times you have been asked to input a number. Start with 2\n";
do
{
cout << "Enter the number\n";
cin>> urnumber;
thenumber++;
}
while (urnumber==thenumber && thenumber<15);
if (urnumber!=thenumber)
{
cout<< "Game Over! You Lose";
cin.ignore ();
}
else if (thenumber=15)
{
cout<< "Congratulations You've passed level 1! Now you have to enter the number double the number of times you've been asked! The current number is 15!";
level2 ();
}
if (urnumber!=rightanswer)
{
cout<< "Game Over! You Lose!";
cout<< "Press Enter To Exit...";
cin.ignore();
}
else
{
cout<< "You Win! More Levels Coming Soon!";
cout<< "Press Enter to Exit..";
cin.ignore();
}
return 0;
}
#include <iostream>
int go_to;
int thenumber=1;
int urnumber;
int level2 ()
{
int doubler=15;
int rightanswer=30;
do
{
std::cout<< "Enter The Number";
std::cout;
rightanswer=thenumber+doubler;
thenumber++;
doubler++;
}
while (urnumber==rightanswer && rightanswer<50);
return 0;
}
usingnamespace std;
int main ()
{
int doubler=15;
int rightanswer=30;
cout<< "The Rules of the Game are: enter the number equal to the number of times you have been asked to input a number. Start with 2\n";
do
{
cout << "Enter the number\n";
cin>> urnumber;
thenumber++;
}
while (urnumber==thenumber && thenumber<15);
if (urnumber!=thenumber)
{
cout<< "Game Over! You Lose";
cin.ignore ();
}
elseif (thenumber=15)
{
cout<< "Congratulations You've passed level 1! Now you have to enter the number double the number of times you've been asked! The current number is 15!";
level2 ();
}
if (urnumber!=rightanswer)
{
cout<< "Game Over! You Lose!";
cout<< "Press Enter To Exit...";
cin.ignore();
}
else
{
cout<< "You Win! More Levels Coming Soon!";
cout<< "Press Enter to Exit..";
cin.ignore();
}
return 0;
}
Code tag please!
What error did you get? can you post it here?
It will be useful to locate the error in your code.
put it after the #include so that you don't have to call std:: so many times
2- I dont understand the use of level2()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int level2 ()
{
int doubler=15;
int rightanswer=30;
do
{
std::cout<< "Enter The Number";
std::cout;
rightanswer=thenumber+doubler;
thenumber++;
doubler++;
}
while (urnumber==rightanswer && rightanswer<50);
return 0; //this function will always return a value: 0
}
level2() always return 0, is that what you wanted? if you want to print and do things, you could've used void function instead of having a int value return function