Sorry guys, i'm an absolute newbie and need help with this code.
I'm trying to get the program to shutdown the computer once a numeral password has been entered. Can you all help to improve my code?
#include <iostream>
#include <cmath>
#include <windows.h>
usingnamespace std;
int main ()
{
int a;
cout<<"what is the password?" <<endl;
cin>>a;
if (a==3) {
cout<<"good job"<<endl;
system ("pause");
system ("shutdown/p");
} else {
if a<3;
cout<<"Wrong Password try again"<<endl;
cin>>a;
}
return 0;
The program needs a loop, for example a while loop. Otherwise, only the very first cin>>a; input is useful.
As for the if-else structure, if the first test (a==3) is not true, the else clause can handle the other possibilities without the need for any further if conditions.
#include <iostream>
#include <cmath>
#include <windows.h>
usingnamespace std;
int main ()
{
int a;
cout<<"what is the password?" <<endl;
cin>>a;
while (a != 3)
{
cout<<"Wrong Password try again"<<endl;
cin >> a;
}
cout<<"good job"<<endl;
system ("pause");
system ("shutdown /p");
return 0;
}
Dang, Ninja'd Had to answer a phone before I hit submit.
Thanks guys(Gals). The code works like a charm! I've learnt how to handle this already! Thanks Stewbond!
@MiiNiPaa:
Your code has an error at Return 0... I have no idea how to solve it. You mind dropping me an email to help me with that?