0

My while, if and else are getting the same error: expected unqualified-id before 'while'

Whats the problem? with if/else: #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;} With while: int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 1; }

30th Oct 2016, 4:45 AM
Sammy Bunckly
Sammy Bunckly - avatar
3 Réponses
+ 5
#include <iostream> using namespace std; int main(){ int a = 0; while (a != 876) { cout << "Enter Code" << endl; cin >> a; if (a != 876) { cout << "Error 876: Wrong Code" << endl; } } cout << "Welcome." << endl; }
30th Oct 2016, 9:01 AM
Zen
Zen - avatar
+ 2
hey you made a lot of mistakes!!!! this is the correct code which you were trying #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;} int num = 1; while (num < 6) { cout << "Number: " << num << endl; num = num + 1; } }
30th Oct 2016, 7:12 AM
Mohammed Zameeruddin
Mohammed Zameeruddin - avatar
0
Ty
31st Oct 2016, 4:52 PM
Sammy Bunckly
Sammy Bunckly - avatar