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)
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.
+ 4
Sorry... I didn't understand the last question.
+ 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;
}
+ 2
God, save this man, it works!
+ 1
But can i compare want and deposite/credit?
+ 1
is it real to do this: what==credit ?
+ 1
No, not awful, silly ;-) its a joke sorryđ
0
thanks people)