Can you explain your reasoning behind that. You lost me.
I am making a program that calculates 2 numbers. You input the operator by typing "add", "subtract", "multiply", or "divide". If the user inputs something besides one of these words, the program tells the user what to input, and goes back to the operator entry point.
an if-else statement llooks like this:
I am aware of that, Okiesmokie. I only put the part of the code that was defective. But, to make you happy, here is the entire source code.
Code:
#include <iostream.h>
int main()
{
char op[9] = "";
int firstNo = 0;
int secNo = 0;
cout<<"Enter first number:\t";
cin>>firstNo;
cout<<"Enter second number:\t";
cin>>secNo;
cout<<"Enter operation type:\t";
cin>>op;
cout<<endl;
if(op=="add")
{
cout<<firstNo<<" + "<<secNo<<" = "<<firstNo + secNo;
}
else if(op=="subtract")
{
cout<<firstNo<<" - "<<secNo<<" = "<<firstNo - secNo;
}
else if(op=="multiply")
{
cout<<firstNo<<" * "<<secNo<<" = "<<firstNo * secNo;
}
else if(op=="divide")
{
cout<<firstNo<<" / "<<secNo<<" = "<<firstNo / secNo;
}
else
{
cout<<"Please enter 'add', 'subtract', 'multiply', or 'divide' as operation type";
goto cout<<"Enter operation type:\t";
}
return 0;
}