Ok, I've gotten better at coding since the last thread and managed to do the previous 3 weeks of coursework. Although this one is throwing me for a loop, an infinite loop to be exact
. For this weeks assignment we have to make a calculator that loops until the user inputs "done". The calculator part works perfectly, although I'm having trouble getting it to loop properly.
Can someone please point me in the right direction?
(I may have more questions about the next three assignments that I have to do, since we are starting to get into functions and I want to learn this.)
Here's my current code:
Can someone please point me in the right direction?
(I may have more questions about the next three assignments that I have to do, since we are starting to get into functions and I want to learn this.)
Here's my current code:
Code:
#include <iostream>
using namespace std;
int main ()
{
int var1;
int var2;
int math;
char done = math;
done=tolower(done);
{
cout << "Please enter two operators" << endl;
cin >> var1 >> var2;
cout << endl;
cout << "Please choose an operation" << endl;
cout << "1. Addition" << endl;
cout << "2. Subtraction" << endl;
cout << "3. Multiplication" << endl;
cout << "4. Division" << endl;
cout << "5. Enter 'done' to exit calculator" << endl;
cin >> math;
cout << endl;
if (math == done)
{
cout << "Thanks for using the calculator." << endl;
return 0;
}
switch (math)
{
case 1:
cout << var1 + var2 << endl;
break;
case 2:
cout << var1 - var2 << endl;
break;
case 3:
cout << var1 * var2 << endl;
break;
case 4:
if (var2 != 0)
cout << var1 / var2 << endl;
else
cout << "ERROR: Cannot divide by zero." << endl;
break;
}
}
return 0;
}