dimanche 28 août 2016

how to ask for input again c++

First of all im sorry if the code look weird here but i dont know how to set it up good. But my question is how i ask the user if he/she wants to input again. ex. do you want to calculate again? yes or no.

}int main()

{

int a;
cout << endl << "Write 1 for addition and 0 for substraction:" << endl;
cin >> a;

// addition
if (a == 1) {
    cout << "You are now about to add two number together, ";
    cout << "enter a number: " << endl;
    int b;
    cin >> b;
    cout << "one more: " << endl;
    int c;
    cin >> c;
    cout << b + c;
}
//Substraction
else if (a == 0) {
    cout << "enter a number: " << endl;
    int b;
    cin >> b;
    cout << "one more: " << endl;
    int c;
    cin >> c;
    cout << b - c;
}
//If not 1 or 0 was called
else {
    cout << " da fuck " << endl;

}

return 0;

}

Aucun commentaire:

Enregistrer un commentaire