0

please, fix this owful code

#include <iostream> using namespace std; int main() { char want = 'w'; char deposit = 'd'; char credit = 'c'; cout << "what you want:"; cin >> want; if ('w'= 'c'){ cout << "credit"; } if ('w'= 'd' ){ cout << "deposit"; } return 0; } Output is only "what you want" Maybe you can make it with switch(i tried, but field)

20th Mar 2018, 6:37 PM
Morgenstern
Morgenstern - avatar
8 Answers
+ 6
First of all, to compare you have to use '=='. Second, 'w' will never be equal to d or c. The right code for that is: cout<<"what you want? (d/c):";//deposite or credit cin >> want; if(want=='c') { cout << "credit" ;} if(want=='d'){ cout << "deposit" ; } Comment if it helped.
20th Mar 2018, 6:46 PM
Fabio
+ 4
Sorry... I didn't understand the last question.
20th Mar 2018, 6:56 PM
Fabio
+ 3
//Well, you can compare strings like this: #include <iostream> #include <string> using namespace std; int main() { string uservar = "Morgenstern"; string someuser =""; cout << "type a sololearner user:"; cin >> someuser; if(!uservar.compare(someuser)){ cout<<"He asked a question"; } //or if(uservar =="Morgenstern") { //It is the same. But it's better the first. } return 0; }
20th Mar 2018, 7:55 PM
Fabio
+ 2
God, save this man, it works!
20th Mar 2018, 6:51 PM
Morgenstern
Morgenstern - avatar
+ 1
But can i compare want and deposite/credit?
20th Mar 2018, 6:54 PM
Morgenstern
Morgenstern - avatar
+ 1
is it real to do this: what==credit ?
20th Mar 2018, 7:07 PM
Morgenstern
Morgenstern - avatar
+ 1
No, not awful, silly ;-) its a joke sorry😂
20th Mar 2018, 7:30 PM
dieserrapha
dieserrapha - avatar
0
thanks people)
20th Mar 2018, 9:53 PM
Morgenstern
Morgenstern - avatar