help me write a program
-
write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..
Member 12968703 wrote:
its say error expected '(' before 'else'..
The error message already told what is the problem: just read it and check the code that it points out, in this case the
else
statement: that particular line is incorrect and needs fixing.GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
-
write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..
scanf("%p" , &password); // should be %d for integer values
if(password=12345); // should be '==' for comparison test
{
printf("Your password is correct");
}if else(password!=12345); // Removed the 'if', this is a continuation of the previous if statement
-
scanf("%p" , &password); // should be %d for integer values
if(password=12345); // should be '==' for comparison test
{
printf("Your password is correct");
}if else(password!=12345); // Removed the 'if', this is a continuation of the previous if statement
-
I mean the right parens on the lines with ifs. The one on this line :
if(password=12345);
Will cause the printf to always execute.
-
write a program that can be enter the password , if the correct password,the output will display "Your password is correct" if not the output will display "Your password is incorrect" and prompted to re enter a password. this is my code but i still cant figure out what its prolblem.:confused::confused: #include int main() { int password=12345; printf("Please insert your password:\n"); scanf("%p" , &password); if(password=12345); { printf("Your password is correct"); } if else(password!=12345); { printf("Your password is incorrect"); } } its say error expected '(' before 'else'.. kindly anybody can help me..please..
-
#include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..
-
#include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..
You do it be creating a loop, using a
do
,while
orfor
statement. In pseudo code something like:Set a retry count
While retry is not zero
Check password
If password is correct
Then break
Else
retry = retry - 1
If retry is zero
Then display error message
End WhileSee if you can turn that into C code.
-
#include int main() { float number = 123456; int pass; printf("Please enter your password:\n"); scanf("%d",&pass); if (pass==number) { printf("Your password is correct.\n"); } else { printf("Your password is incorrect.\n"); } } i already write the program but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..
Member 12968703 wrote:
if (pass==number)
Comparing an
int
to afloat
will rarely, if ever, work.Member 12968703 wrote:
but i dont know how to make a prompted to re enter a password if i enter a wrong password..i really dont know..and i hope u can help me..
To continue the prompting until the correct password is entered, you'll need to use a loop. Something like:
do
{
...
} while (password != 12345);"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles