I'm trying to create a small program for a beginner's C++ class. Basically, we have to take user input of 2 numbers and then output the sum, difference, product, and quotient of each. I'm trying to make mine a bit more user friendly and slightly more difficult that what is probably expected. This is what I have:
#include <iostream>
using namespace std;
int main(void)
{
char ans1; //I go ahead and declare my variables...
double ans2;
double ans3;
float add;
float subtract;
float mult;
float divide;
float remainder;
/*--Starting here, I prompt the user to specify what they want to do with
their two number choices--*/
cout<<" ------------------------------------------- ";
cout<<" Simple math ";
cout<<" ------------------------------------------- ";
cout<<"Choose what you want to do with two numbers:\n\na. Addition\nb. Subtraction\nc. Multiplication\nd. Division";
cout<<"\n\nChoose a, b, c, or d: ";
cin>>ans1;
if(ans1=='a'){ //This line starts my if loop that branches the programs actions according to the user's input.
cout<<"You've chosen Addition. Please enter two numbers separated by spaces:\n\n";
cin>>ans2>>ans3;
cout<<"The sum is "<<ans2+ans3<<".";
cin.get();
}
else if(ans1=='b'){
cout<<"You've chosen Subtraction. Please enter two numbers separated by spaces:\n\n";
cin>>ans2>>ans3;
cout<<"The difference is "<<ans2-ans3<<".";
cin.get();
}
else if(ans1=='c'){
cout<<"You've chosen Multiplication. Please enter two numbers separated by spaces:\n\n";
cin>>ans2>>ans3;
cout<<"The product is "<<ans2*ans3<<".";
cin.get();
}
else if(ans1=='d'){
cout<<"You've chosen Division. Please enter two numbers separated by spaces:\n\n";
cin>>ans2>>ans3;
remainder=ans2%ans3;
if (remainder==0){
cout<<"The quotient is "<<ans2/ans3<<".";
cin.get();
else {
cout<<"The quotient is "<<ans2/ans3<<"With a remainder of "<<remainder".";
cin.get();
}
}
cin.get();
}
cin.get();
return 0;
}
Dev-C++ keeps giving me errors. Anyone care to hlep?