Recalling the program
Aug 16, 2012 at 4:25am UTC
I am trying to make it so after the program is finished with the process that the user did. For the computer to reset and go back to the beginning of the program.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
#include <iostream>
using namespace std;
int main()
{
int result;
int firstnumber;
int secondnumber;
string TypeofMath;
cout << "Enter the type of math you are going to do." << endl;
cout << "Type HELP to receive a list of all types available right now." << endl;
cin >> TypeofMath;
if (TypeofMath == "Addition" )
{
cout << "Enter the number you would like to add something to." << endl;
cin >> firstnumber;
cout << endl;
cout << "Enter the number you would like to add to " << firstnumber << "." << endl;
cin >> secondnumber;
cout << endl;
cout << "Adding, " << firstnumber << " and " << secondnumber << ". . ." << endl;
cout << endl;
result = firstnumber + secondnumber;
cout << result << " is the answer." << endl;
cout << endl;
cout << "Number Line;" << endl;
cout << firstnumber << " + " << secondnumber << " = " << result << endl;
}
if (TypeofMath == "Subtraction" )
{
cout << "Enter the number you would like to subtract something from." << endl;
cin >> firstnumber;
cout << endl;
cout << "Enter the number you would like to subtract from " << firstnumber << "." << endl;
cin >> secondnumber;
cout << endl;
cout << "Subtracting, " << secondnumber << " from " << firstnumber << ". . ." << endl;
cout << endl;
result = firstnumber - secondnumber;
cout << result << " is the answer." << endl;
cout << endl;
cout << "Number Line;" << endl;
cout << firstnumber << " - " << secondnumber << " = " << result << endl;
}
if (TypeofMath == "Multiplication" )
{
cout << "Enter the number you would like to multiply." << endl;
cin >> firstnumber;
cout << endl;
cout << "Enter the number you would like to multiply " << firstnumber << " by." << endl;
cin >> secondnumber;
cout << endl;
cout << "Multiplying " << firstnumber << " by " << secondnumber << ". . ." << endl;
cout << endl;
result = firstnumber * secondnumber;
cout << result << " is the answer." << endl;
cout << endl;
cout << "Number Line;" << endl;
cout << firstnumber << " * " << secondnumber << " = " << result << endl;
}
if (TypeofMath == "Division" )
{
cout << "Enter a dividend." << endl;
cin >> firstnumber;
cout << endl;
cout << "Enter a divisor." << endl;
cin >> secondnumber;
cout << endl;
cout << "Dividing " << firstnumber << " by " << secondnumber << ". . ." << endl;
cout << endl;
result = firstnumber / secondnumber;
cout << result << " is the answer." << endl;
cout << endl;
cout << "Number Line;" << endl;
cout << firstnumber << " / " << secondnumber << " = " << result << endl;
}
if (TypeofMath == "HELP" )
{
cout << endl;
cout << "Addition" << endl;
cout << "Subtraction" << endl;
cout << "Multiplication" << endl;
cout << "Division" << endl;
}
while (1);
return 0;
}
All I need is for someone to give me the piece of code
Aug 16, 2012 at 4:28am UTC
put it in a loop:
1 2 3 4
while ( some_condition )
{
// code
} // <--- end of loop
Once the program reaches
end of loop
, if
some_condition
is true,
// code
will repeat.
If
some_condition
is false, the loop exits.
Aug 16, 2012 at 4:32am UTC
Thanks man! It worked.
Topic archived. No new replies allowed.