Clearing A getline(cin, string) to use again


Okay so I am royaly frustrated as all hell right now I spent 3 hours looking around the internet to figure out how to solve this problem and I have had no success
so what I am trying to do is when it goes back to getline(cin, sign1input) the value is cleared so when I type in middle path or right path it goes to that cause when it comes back to
getline(cin,sign1input) it only accepts the value Left Path cause that is the only one that I have go back since it is a text based game so
I need to know how to clear sign1input so I can use it again I have tried the \0 that didn't work neither did cin.erase,cin.clear,cin.erase or none of that I can understand any of the forums on how to fix this so
please tell me what I need to do tell me where I need to put it and why It needs to be their I use visual studio pro 2013 and I cannot figure this out please help !!!!!
BTW... All of the goto's and if statments do work correctly its the erasing of the string sign1input I cant figure out Thank You !

cout << "" << endl;
cout << "Shack (Left Path)" << endl;
cout << "" << endl;
cout << "? (Middle Path)" << endl;
cout << "" << endl;
cout << "Activisionia (Right Path)" << endl;
cout << "" << endl;
gobacktosign1:
cout << "Type Left Path, Middle Path, or Right Path To Continue..." << endl;
cout << "" << endl;

// Make the left path destination first then make the right path destination

retypethesign:

THIS IS THE MORE IMPORTANT AREA THIS IS NOT CODE IN MY PROGRAM !!!!!!!!!!!!!!

getline(cin, sign1input);
if (sign1input == "Left Path" || sign1input == "left path" || sign1input == "LEFT PATH")
{
cout << "You Are Going On Ward To The Shack" << endl;
cout << "" << endl;
goto shackpath1;


}

if (sign1input != "Left Path" || sign1input != "left path" || sign1input != "LEFT PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}

if (sign1input == "Middle Path" || sign1input == "middle path" || sign1input == "MIDDLE PATH")
{
cout << "You Continue On The Middle Path and You Take Your Breath Type Continue to Continue" << endl;
cout << "" << endl;
goto deathsign1;
}

if (sign1input != "Middle Path" || sign1input != "middle path" || sign1input != "MIDDLE PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}

if (sign1input == "Right Path" || sign1input == "right path" || sign1input == "RIGHT PATH")
{
cout << "You Are Onward To Actiovisionia Type Money Hungry To Go Forth" << endl;
cout << "" << endl;
goto activisionia1;
}

if (sign1input != "Right Path" || sign1input != "right path" || sign1input != "RIGHT PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}
1) Always post using code tags so that the code is readable
2) Use of goto is bad design
3) I don't see where label shackpath1 is defined so don't know what path it takes when user enters "Left Path", so can't comment on the execution path after that
4) Assuming sign1input is an char array you can use sign1input[0] = '\0'; to clear its contents.
5) sign1input != "Middle Path" (and all other similar comparisons) do not work, they are comparing to pointer not the contents of the pointers
For proper comparison use "strcmp"
4) Before you "strcmp" use "tolower" on the input so that you will have to only compare once with lower case strings like "left path"
Well Shackpath is apart of a code to go to the shack and it does work it is coded the same as my other paths I need to know exactly where I need to put what in the code up their so it will work and explain what is and why it needs to go their pretty much I needed it so I can insert it in my compiler (vs 2013 pro) so I can finally continue on my project Thanks !

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
cout << "" << endl;
cout << "Shack (Left Path)" << endl;
cout << "" << endl;
cout << "? (Middle Path)" << endl;
cout << "" << endl;
cout << "Activisionia (Right Path)" << endl;
cout << "" << endl;
gobacktosign1:
cout << "Type Left Path, Middle Path, or Right Path To Continue..." << endl;
cout << "" << endl;

// Make the left path destination first then make the right path destination

retypethesign:

THIS IS THE MORE IMPORTANT AREA THIS IS NOT CODE IN MY PROGRAM !!!!!!!!!!!!!!

getline(cin, sign1input);
if (sign1input == "Left Path" || sign1input == "left path" || sign1input == "LEFT PATH")
{
cout << "You Are Going On Ward To The Shack" << endl;
cout << "" << endl;
goto shackpath1;


}

if (sign1input != "Left Path" || sign1input != "left path" || sign1input != "LEFT PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}

if (sign1input == "Middle Path" || sign1input == "middle path" || sign1input == "MIDDLE PATH")
{
cout << "You Continue On The Middle Path and You Take Your Breath Type Continue to Continue" << endl;
cout << "" << endl;
goto deathsign1;
}

if (sign1input != "Middle Path" || sign1input != "middle path" || sign1input != "MIDDLE PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}

if (sign1input == "Right Path" || sign1input == "right path" || sign1input == "RIGHT PATH")
{
cout << "You Are Onward To Actiovisionia Type Money Hungry To Go Forth" << endl;
cout << "" << endl;
goto activisionia1;
}

if (sign1input != "Right Path" || sign1input != "right path" || sign1input != "RIGHT PATH")
{
cout << "You Cannot Type That Please Try Again" << endl;
cout << "" << endl;
goto retypethesign;
}
I will add the clearing of the string sign1input using the sign1input = '\0' did not work as far as I know but then again left path is the only one that is working.....
Topic archived. No new replies allowed.