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; }
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;
}
+ 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;
}
}
0
Ty