I am trying to create a calculator but this happens.. Here's my code. Please help me fix it and give some explanation:
#include <iostream>
using namespace std;
int main()
{
int a;
int b;
string c;
string d;
cout<<"Enter No. 1: ";
cin>>a;
cout<<"Enter Operation: ";
cin>>c;
cout<<"Enter No. 2: ";
cin>>b;
cout<<"So you want me to solve this: ";
cout<<a<<c<<b;
cout<<"Type Yes or No";
cin>>d;
if(d="yes"){
switch(c)
{
case '+':
cout << a+b;
break;
case '-':
cout << a-b;
break;
case '*':
cout << a*b;
break;
case '/':
cout << a/b;
break;
}
}
else{
return 0;
}
}
This is the eroor of the code when compiled pleasee fix this code ima noob:
main.cpp: In function ‘int main()’:
main.cpp:21:9: error: could not convert ‘d.std::basic_string<_CharT, _Traits, _Alloc>::operator=, std::allocator >(((const char*)"yes"))’ from ‘std::basic_string’ to ‘bool’
if(d="yes"){
~^~~~~~
main.cpp:22:17: error: switch quantity not an integer
switch(c)
Aucun commentaire:
Enregistrer un commentaire