Hi,
I don't know where i when wrong... But my program doesn't want to loop properly.
I was ask to make a Simple calculator that will loop the ans till giving a exit.
here is what i got...
#include <iostream>
#define NEWLINE "\n\n";
using namespace std;
int main()
{
char operators, /*counter*/;
float num1, num2, ans;
int cal;
//counter = 0;
// while (cal == counter )
{
cout << "** MY OWN CALCULATOR **";
cout << NEWLINE;
cout << "Select + , - , * , / ";
cout << NEWLINE;
cout << "Start calculating!";
cout << NEWLINE;
cin >> num1;
cout << NEWLINE;
cin >> operators;
cout << NEWLINE;
cin >> num2;
cout << NEWLINE;
switch(operators)
{
case '+':
cout << "=";
cout << NEWLINE;
cout<< num1 + num2<< endl;
cout << NEWLINE;
num1 = ans;
// counter = counter + 1;
break;
case '*':
cout << "=";
cout << NEWLINE;
cout<< num1 * num2<< endl;
cout << NEWLINE;
num1 = ans;
// counter = counter + 1;
break;
case '/':
cout << "=";
cout << NEWLINE;
cout<< num1 / num2<< endl;
cout << NEWLINE;
num1 = ans;
// counter = counter + 1;
break;
case '-':
cout << "=";
cout << NEWLINE;
cout<< num1 - num2<< endl;
cout << NEWLINE;
num1 = ans;
// counter = counter + 1;
break;
case 'x':
exit(EXIT_FAILURE);
break;
default:
cout << "ERROR!";
cout << NEWLINE;
cout << "Continue";
cout << NEWLINE;
break;
}
{
/* cout << "To exit press x.";
exit(x);*/
}
}
system ("pause");
return 0;
}