0

Cin and Cout in C++

hi, what is wrong with the following code? it just checks the first IF and print it regardless of the cin was 100 or not! #include <iostream> using namespace std; int main() { int dar; cin >> dar; if (dar = 100) { cout << "the number was 100" << endl; } else { cout << "Damn it again" << endl; } return 0; }

13th Oct 2017, 12:38 PM
Dariush Shiri
Dariush Shiri - avatar
5 Respostas
+ 5
You typed = where it should be ==. Thus,use dar==100. // == is equality, = is assignment.
13th Oct 2017, 12:42 PM
Solo Wanderer 4315
Solo Wanderer 4315 - avatar
+ 2
in which machine r u running this. it looks. very unsual.
13th Oct 2017, 12:40 PM
shobhit
shobhit - avatar
+ 1
Thank you kinshuk, it works now. I just added ==
13th Oct 2017, 12:44 PM
Dariush Shiri
Dariush Shiri - avatar
+ 1
if (dar == 100) {
13th Oct 2017, 12:49 PM
MBZH31
MBZH31 - avatar
0
On solo
13th Oct 2017, 12:43 PM
Dariush Shiri
Dariush Shiri - avatar