I need it in 2 days..plz help me..is urgent!!!

I have problems in "status" problem..I can't loop successfully..can anyone help me to edit my coding???It's very urgent!!!thanks for everything..


#include <iostream>
#include <string>
using namespace std;

int main()

{
restart: string mystr;
cout << "\n" << "What's your password? ";
getline (cin, mystr);
cout << "Your password is set!" << "\n";


int status;
cout << "Please Choose status: " << "\n";
{cin >> status;
switch (status)
{case 1: cout << "Your status is: " << "Please Come In! ";break;
case 2: cout << "Your status is: " << "Do Not Disturb! ";break;
case 3: cout << "Your status is: " << "Out To Lunch! ";break;
case 4: cout << "Your status is: " << "Out For Meeting! ";break;
case 5: cout << "Your status is: " << "Will Be Right Back! ";break;
case 6: cout << "Your status is: " << "Not In! ";break;
};
};


//for looping//
cout << "\n" << "please enter your password: ";
getline (cin, mystr);
cout << "\n" << "status can change! " << "\n";
goto restart;
return 0;
};
Last edited on
You probably want the "restart:" label down before line 14.

That said, what is with with the "goto"? Why not use a regular "while" loop instead?

Syntax:
1) Lines 16..25 don't need their own {...} block.
2) Except following complex type statements (struct, class, union) and constant initializers for them and for arrays, you don't generally need a semicolon following closing-braces.

You are aware that your 'loop' is infinite, right?

Hope this helps.
dear Duoas,
1)May you please teach me how to insert the while loop??
2)for looping part,I want to make password follows the one when I first insert.How to do it?
Sorry cause I do not know their difference.
I want the loop is infinite.
thankz alot for your help.
I appreaciate it indeed.
Last edited on
relax! you still got 2 days... trust me, its more than enough.

for 1) the while loop syntax is
while (/*insert condition to continue loop*/) {
//all your switch codes
}

so if u want an infinite loop while (1) {...} will do nicely.

for 2) you need an if-else statement to check. I guess if you know loops and switch statements, u should know how to do if-else. right?

you need to store the password in the last few lines in another string and compare it with the first one using if-else.

and for the difference between while loops and goto's is i guess while loops are much more developer friendly. easier to read. but technically, i don't know the diff (or if the diff mattered).
Last edited on
but i am not confident in C++.i only attended four weeks class.
this simple coding already make me headache..

dear averageguy,
can u describe it clearly by giving me some example?
do u mean in switch statement,i need to change all the 'case' with 'while'?

i still learn to how to store the password.i hope u can help me if i have problem.
thankz alot..
aiyo...so jialat meh. hahhaa

c++ statements are made to sound like human languages. so... i.e.

1
2
3
while (gas tank is not full) {
       keep pouring in gas
}


in your case would be
1
2
3
4
5
6
7
while(true) { //since u want an infinite loop
     cout, cin
     switch (status)
     case:
     new password
     and stuff...
}


to store things, of course you would need space, right? so you need to reserve a space for the password by declaring another string i.e.
string old_password;

and then storing the passoword into it. after you cin your new password to mystr, compare it to the old password.
Topic archived. No new replies allowed.