Fix and tell me what you did to make it work, kinda at the end of the line with this C++ not doing what I want D:< | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Fix and tell me what you did to make it work, kinda at the end of the line with this C++ not doing what I want D:<

#include <iostream> using namespace std; int main() { int a; cout << "Enter Code" << endl; cin >> a; if (a=876) cout << "Welcome." << endl; else cout << "Error 876: Wrong Code" << endl; }

30th Oct 2016, 4:02 AM
Sammy Bunckly
Sammy Bunckly - avatar
2 Answers
+ 1
You need to use 'if(a == 876)' instead of 'if(a=876)'. That == is comparison operator, = is assignment operator. You are assigning value of 876 to variable a in that if statement. This returns 876, which is not 0, so it's true, so that code after if statement won't be executed only if user inputs 0.
30th Oct 2016, 7:53 AM
Daniel Oravec
Daniel Oravec - avatar
0
Missing some curly brackets.
4th Nov 2016, 10:32 PM
Michael Gailey
Michael Gailey - avatar