#include <iostream>
// writing this line here would be better
//instead of inside main().
usingnamespace std;
int main()
{
// for beautiful coding
//always add your declarations
//to the beginning.
char o;
int x;
int y;
// it will keep looping as long
//as x isnt equal to -1.
while(x != -1)
{
cout << "enter a number: \n";
cin >> x;
cout << "\n";
cout << "\n";
cout << "1 = multiplication ";
cout << "2 = division ";
cout << "3 = addition ";
cout << "4 = subtraction ";
cout << "-----------------------------------------------------------------------------------------\n";
cout << "enter your choice: \n";
cin >> o;
cout << "enter your last number: \n";
cin >> y;
//it should be == instead of =
//haha sorry i didnt realized it :D
if ((o == 1))
cout << x * y << endl;
elseif ((o == 2))
cout << x / y << endl;
elseif ((o == 3))
cout << x + y << endl;
elseif ((o == 4))
cout << x - y << endl;
else
cout << "you entered an invalid operator\a";
}
return 0;
}
note : "==" is a query while "=" is an assignment.
Create a class say CCalc, and then while the instance of your class is not NULL continue running the program:
1 2 3 4 5 6 7 8 9 10 11 12 13
int main (int argc, char* argv[])
{
do
{
// instantiate instance of your CCalc, say a singleton:
CCalc* pCal = CCalc::GetInstance();
// do calculations etc...
// then when user switches calculator off its destructor is called
// and pCal is deleted and NULL assigned to pointer
} while (pCal);
return 0;
}
well i see no reason about you are being worng but also no reason for me too. it is like chosing the percantage of the milk in a chocolate chosing between do{}while() and while() for a beginner