So I'm trying to make a basic calculator that will use a do-while loop and prompt the user for an answer of whether the user wishes to rerun the calculator from the beginning. My error runs in at the cin for the string literal answer of yes or no my error says >': no operator found which takes a right-hand operand of type 'std::string' (or there is no acceptable conversion)> Please help me. I'm very new and I'm in college in a basic programming class.
int main()
{
double x;
double z;
char o;
string a;
char Y, y;
do
{
cout << "Please input a value for x: " << endl;
cin >> x;
cout << "Please input a value for z: " << endl;
cin >> z;
cout << "Please pick an operation to do: * / + -" << endl;
cin >> o;
switch (o) {
case '+':
cout << x << " + " << z << " = " << x + z << endl;
break;
case '-':
cout << x << " - " << z << " = " << x - z << endl;
break;
case '*':
cout << x << " * " << z << " = " << x*z << endl;
break;
case '/':
if (z != 0)
{
x / z;
cout << x << " / " << z << " = " << x / z << endl;
}
else
{
cout << "Can not divide by zero! Nice try, Pedersen!" << endl;
}
break;
default:
cout << "/n/n/tThank you for using my calculator!" << endl << endl;
}
system("cls");
cout << "/n/n/tDid you want to run the calculator again?" << endl << endl;
cin >> a;
}while (a == "Yes" || a == "yes");
system("pause");
return 0;
Aucun commentaire:
Enregistrer un commentaire