I'm having a problem converting the password program to a switch this is the first choice in the program Menu: In your main function, present the user with a numbered menu (choices 1, 2, or 3) that allows them to run the following tasks. You MUST implement the menu using a switch statement.
1. For the first choice, ask the user for a password. Then ask them to type their password again. Compare what they typed each time and provide a message indicating whether or not their password matched. Here's my code so far Id appreciate any help
/*Menu: In your main function, present the user with a numbered menu
(choices 1, 2, or 3) that allows them to run the following tasks.
You MUST implement the menu using a switch statement.*/
#include<iostream>
#include<string>
usingnamespace std;
int main()
/*
1. For the first choice, ask the user for a password. Then ask them to type their password again.
Compare what they typed each time and provide a message indicating whether
or not their password matched.*/
{
int choice;
constint password = 1,
constint division_woohoo = 2,
constint division_2;
char pass1, pass2;
cout << "Enter choice 1, 2 or 3";
cin >> choice;
switch (choice)
{
case 1:
cout << "Enter your 6 character password \n";
cin >> pass1;
cout << "re-enter your password /n";
cin >> pass2;
case pass1 == pass2;
}
system("pause");
return 0;
}
thanks for any help
the code you need help with here.
I'm not quite sure what some of your variables are intended for, but here's a basic sort of set-up which you might find useful, although I'm sure others can improve upon it:
Your requirements. Menu: In your main function, present the user with a numbered menu (choices 1, 2, or 3) that allows them to run the following tasks. You MUST implement the menu using a switch statement. 1. For the first choice, ask the user for a password. Then ask them to type their password again. Compare what they typed each time and provide a message indicating whether or not their password matched.
switch (choice)
{
case 1:
cout << "Enter your 6 character password \n";
cin >> pass1;
cout << "re-enter your password /n";
cin >> pass2;
if (pass1 == pass2)
// <--- Do something.
break;
case 2:
break;
case 3:
break;
default:
break;
}
You have a good start, but it fell apart at line 37.
The if statement is just a guess here.
Without the "break" statement to end the case it would fall through to the next case statement. Unless you have code to make sure that "choice" will always have a matching case statement you should end the switch with the "default" case. Here you can put a message to explain the problem before leaving the switch and trying again.
If you have learned about functions you could use the switch to call a function to do the work. This would be a better use of the switch than trying to put all your code in the case statements.