Hello...
We were asked to create a simple calculator program in our C++ subject by using loops only. i have a problem in creating a loop in the multiplication and division operation so please can anyone help me on this please. and also during the operation selection, if ill enter a character it wont go back to the main program. by the way, my compiler is DevC++.
I need help badly..here's my code below...
#include <iostream.h>
#include <stdlib.h>
#include <dos.h>
int main()
{
Begin:
system("CLS");
int options;
float fnum, snum, i, sum, diff, product, quotient;
cout << "Simple Calculator\n\n"; /*Operation Option*/
cout << "1  Addition" << endl;
cout << "2  Subtraction" << endl;
cout << "3  Multiplication" << endl;
cout << "4  Division" << endl;
cout << "5  Quit Program\n\n";
cout << "Please select your operation: ";
cin >> options;
switch (options) {
/*Addition*/
case 1: cout << "You selected the ADDITION OPERATION.\n\n";
cout << "Enter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;
for(i=fnum; i>=0; i) {
sum=snum++;
}
cout << "Answer is " << sum << endl;
system("PAUSE");
goto Begin;
break;
/*Subtraction*/
case 2: cout << "You selected the SUBTACTION OPERATION.\n\n";
cout << "Enter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;
for(i=snum; i>=0; i) {
diff=fnum;
}
cout << "Answer is " << diff << endl;
system("PAUSE");
goto Begin;
break;
/*Multiplication*/
case 3: cout << "You selected the MULTIPLICATION OPERATION.\n\n";
cout << "Enter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;
for(i=snum; i<=fnum; i++) {
product=fnum++;
}
cout << "Answer is " << product << endl;
system("PAUSE");
goto Begin;
break;
/*Division*/
case 4: cout << "You selected the DIVISION OPERATION.\n\n";
cout << "Enter the first number: ";
cin >> fnum;
cout << "Enter the second number: ";
cin >> snum;
for(i=0; i<=fnum; i++) {
for(i=0; i<snum; i++)
quotient=quotient++;
}
cout << "Answer is " << quotient << endl;
system("PAUSE");
goto Begin;
break;
/*Exit Program*/
case 5: exit(0);
default: cout << "\n\nPlease enter the correct option." ;
system("PAUSE");
goto Begin;
break;
}
system("PAUSE");
return 0;
}
im still working out of this program but as of now i need help badly.
i appreciate your help and thank you very much.
im looking forward on it..
