Counting game for my project help!!!! i really need it...

i am having a problem in my game where i start to count from 1 to 10, can someone help me improve the codes? whenever i start to loop, it couts every "sorry start again!" and whenever i answer it correctly it still couts the sorry start again.. sorry for the noob codes.


here's the code

#include<iostream.h>
#include<stdio.h>
#include<conio.h>

main()
{

int num=0;
char name[20],sub;

cout<<"HELLO!!!! PLEASE ENTER YOUR NAME: ";
gets(name);

clrscr();

cout<<"Hello "<<name<<", this is a game about counting and questions about life.";
cout<<"\nyou have to count in correct order for you to continue to the next level,";
cout<<"\nevery level has a question about the creator of this game, if you answer it \ncorrectly,you will proceed to the next level";
cout<<"\nAre you ready? START!!";



cout<<" Please enter the first number: ";
cin>>num;
do{
if (num != 1)

cout<<"Sorry! start again!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=2)

cout<<"Sorry! start again!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=3)

cout<<"Sorry! start again!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=4)

cout<<"Sorry! start again!!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=5)

cout<<"Sorry! start again!!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=6)

cout<<"Sorry! start again!!!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=7)

cout<<"Sorry! start again!!!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=8)

cout<<"Sorry! start again!!!!!";

else
{
cout<<" please enter the next number: ";
cin>>num;
}
if (num !=9)

cout<<"Sorry! start again!!!!!";

else
{
cout<<" please enter the last number of level 1: ";
cin>>num;
}
if (num == 10)
{
cout<<"YOU'RE GOOD!! But To finish the game, answer this question first";
cout<<"\nWhat is the Middle initial of Napoleon Basan?: ";
cin>>sub;

if (sub == 'A')
cout<<"CONGRATULATIONS!! YOU FINISHED THE GAME!!";

else
cout<<"SORRY,GAME OVER";
} }while (num<=10);

return(0);

}
After you win the game you need a way of jumping out of the loop. You can use either return 0 or continue to get out of the loop. f You would place these statements just below line cout<<"CONGRATULATIONS!! YOU FINISHED THE GAME!!";. Also, if you have knowledge of arrays you could shorten down this code a whole lot using for loops.
uhm, when i placed return or continue, it says that "Misplaced else in function main" and also, whenever i write a number then if i input it not in order it displays all the sorry start again..
Was it working before with no problem? or are these problems you had before putting in the return/continue statement?
You would have to use brackets, otherwise the compiler won't be able to associate the "else" with the proper "if"
Hello,

I'm new here and its been a while since I've practiced. But I would agree with ModShop.
uhm where exactly do i have to place the brackets?
1
2
3
4
5
6
7
8
9
10
if( some_condition )
{
  // here, you put whatever code you want run when
  //  'some_condition' is true
}
else
{
  // here, you put whatever code you want run when
  //  'some_condition' is false
}
Topic archived. No new replies allowed.