0

Why is the output to my code changing?

#include <iostream> using namespace std; int main(){ cout<<"please enter password"; int a; cin>> a; if (a==1234){cout<<'correct';} cout<<'try again'; return 0; } when I type it into the compiler I get series of numbers. update; even though I've copied and pasted the code now I'm get errors. I don't understand why a code would read different from one day to the next.

4th Nov 2016, 7:14 PM
new
new - avatar
1 Réponse
+ 4
Make sure you're using double quotes for strings, single quotes indicate characters. Also, put an else statement after the if statement, otherwise both correct and try again could run at the same time. #include <iostream> using namespace std; int main() { int a; cout << "Please enter password: " cin >> a; if (a == 1234) cout << "Correct"; else cout << "Try again"; return 0; }
4th Nov 2016, 7:21 PM
Cohen Creber
Cohen Creber - avatar