bacis progam problems

#include <iostream>

using namespace std;

int main()
{
int age;

cout<<"Type a number between 1 and 10: ";
cin>> age;
cin.ignore();
if ( age < 10 ); {
cout<<"Yay you can follow instructions\n";
}
if ( age >= 11 ); {
cout<<"were going to try this again and you going to do it right\n";
}
for ( int x; age < 10; ); {

cout<<"Type a number between 1 and 10: ";
cin>> age;
cin.ignore();
if ( age < 10 ); {
cout<<"Yay you can follow instructions\n";
}
if ( age > 10 ); {
cout<<"were going to try this again and you going to do it right\n";
}
cin.get();
}
}

when i use this program is shows both responses at the same time, why does it do this



Answer this question

bacis progam problems

  • Mohammad Syed

    Your if-statements are valid but almost certainly not what you wanted

    if (age < 10); {

    What you have is equivalent to:

    if (age < 10) { /* do nothing */ }

    {
       cout << ...
    }

    if (age >= 11) { /* do nothing */ }

    {
       cout << ...
    }

    If you compile with warning level 3 (/W3) you get:

    kk9.cpp(14) : warning C4390: ';' : empty controlled statement found; is this the intent
    kk9.cpp(17) : warning C4390: ';' : empty controlled statement found; is this the intent



  • rstevens

    My earlier response does answer your question - but I'll restate it

    Your if-statments are empty (because of the misplaced ;) therefore your calls to cout are not guarded and thus they are both executed.



  • krhoover

    thanks sorry im a noob
  • Arkcann

    helpful but it doesn't answer my questions
  • bacis progam problems