Overclock.net - An Overclocking Community - View Single Post - We lost our programming virginity
View Single Post
post #180 of (permalink) Old 11-13-2009, 08:07 AM
sailerboy
New to Overclock.net
 
Join Date: Jun 2008
Location: Huntington Beach, CA
Posts: 1,195
Rep: 81 (Unique: 72)
change THIS
Code:
    cout << "What do you want to do?" << endl
        << "<1> Add" << endl
        << "<2> Subtract" << endl
        << "<3> Multiply" << endl
        << "<4> Divide" << endl
        << "Selection: ";
    cin >> selection;

    if (selection >= 1 && selection <=4)
    {
        cout << "First number: ";
        cin >> num1;
        cout << "Second number: ";
        cin >> num2;
    }
TO
Code:
    do{cout << "What do you want to do?" << endl
        << "<1> Add" << endl
        << "<2> Subtract" << endl
        << "<3> Multiply" << endl
        << "<4> Divide" << endl
        << "Selection: ";
cin >> selection;
}while(selection < 1 || selection > 4)
    cout << "First number: ";
    cin >> num1;
    cout << "Second number: ";
    cin >> num2;

    }
A do/while loop runs through the loop at least once before checking the boolean statement. It is useful sometimes.


Click to see epic quotes! (Click to show)Warning: Spoiler! (Click to show)
Quote:
Originally Posted by Pir go_quote.gif
Don't you have an AMD pen lying around somewhere? They write a bit slower but at least they always do.
Quote:
Originally Posted by Hephasteus go_quote.gif
CPU's used to have to do more work, they were fighting off wolves with flyswatters, today they are swatting at flys with bazookas.
Quote:
Originally Posted by nathris go_quote.gif
OSX User: Oh look funny dog pictures, I'm going to download them!
"Funny Dog Pictures requires that you type your password"
OSX User: Hurr Durr, OK!.



Join the deaf club...
sailerboy is offline