cin Getting Wrong user Input

So i'm writing a program that will read a text file and it will do certain "functions" the text file will be like a game, and the program will be able to run many different games. The problem i'm having is in one of the "functions" i believe it's the one meant to get a correct choice from a file and a user input and put them into strings, it gets the wrong input. I know this because i tested both strings the "function" writes too. it gets the correct file answer but the user input is always "c" for some reason.
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
#include "stdafx.h"
#include <iostream> 
#include <iomanip> 
#include <fstream> 
#include <string> 
#include <stdlib.h> 

using namespace std; 


int progfiles()
{ 
string a; // correct answer from file
string choiceg; // user input
string x; // each word gets put in her one by one
string z; //standardized message
ifstream inFile; 
string path; //location of game .txt file


system("cls");
cout << "Where is The Game .txt File Located?(don't remove file extension)";
cin >> path; 

filecheckbegin:

inFile.open(path); //putting word into infile "G://test.txt"
if (!inFile) 
{ 
cout << "Unable to open file"; 
goto filecheckbegin; //error message and starts again
}

system("cls");
start:
inFile >> x;	

	if(x == "1") //Display Text 
	{
		while(x != "2") //display to screen untill x is 2
		{
			inFile >> x;
			if(x != "2")
			cout << x << " ";
		}
		goto start;
	}
/////////////////////////Expexted problem below/////////////////////////////////////////////////////////////////////////////////
/////////////////////////Problem occurs at this portion of reading the text file////////////////////////////////////////////////
//1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2
//8 i 7 3 4 You continue on picking up speed toget there first.. and.. Oh No, You accidentally bumped into the walls! 2
//12 5 1 You go over, and as you realize the walls are electrified and thats why the other's are dieing.. 2 6
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	if(x == "8") //get user input and correct choice
	{
		cout << "got input and answer\n";
		cin >> choiceg;
		inFile >> a;
		cout << a << "\n"; //test to see if it got the correct file answer///
		cout << choiceg << "\n"; //test to see if it got the correct user input///
		system("Pause");
		goto start;
	}
	if(x == "3") // compare user input and correct choice
	{
		if(choiceg == a) //correct choice
		{
			cout << "went to correct\n"; // test to see if it went to correct
			while(x != "5") // 5 starts the text to be displayed for correct answer///
			{
				inFile >> x;
			}
			goto start;
		}
		if(choiceg != a) // death verdict
		{
			cout << "went to incorrect\n"; //test to see if it went to incorrect answer///
			inFile >> x;
			if(x == "4") //4 starts the incorrect text message
			while(x != "2") //display to screen untill x is 2
			{
				inFile >> x;
				if(x != "2")
				cout << x << " ";
			}
			
		}
	}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	if(x == "6") //new line
	{
		cout << "\n";
		goto start;
	}
	if(x == "7") //clear screen
	{
		system("cls");
		goto start;
	}
	if(x == "9") //close file
	{
		inFile.close();
	}
	if(x == "10") //end program then
	{
		cout << "\n\n";
		system("pause");
	}
	if(x == "11") //standard message
	{
		getline(inFile,z);
		goto start;

	}
	if(x == "12")//display standard message
	{
		cout << z;
		goto start;
	}
	if(x == "13")//system pause
	{
		cout << "\n";
		system("pause");
		goto start;
	}
end:
return 0;
}
This is the code, most likely the section that is surrounded with "///" contains the problematic "functions." This is the command Line output
...investigate why they're dieing or continue on your journey?(i-investigate/c-continue) got input and answer
i
c
i
Press any key to continue . . .

The got input and answer are tests to make sure it got both, the first 'i' is my input, the 'c' is what it says my input is, and the 'i' is the correct answer from the file. this is the part of the file that the program reads to get that output

"1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2 8 i 7 3 4 You continue on picking up speed to get to the egg first.. and.. Oh No, You accidentally bumped into the walls! 2 12 5 1 You go over, and as you realize the walls are acidic and thats why the other sperm are dieing.. 2 6"

Any help on this problem is greatly appreciated because i can not figrue it out, it could be right in front of my eyes.. but i need a new set to look at it.
Last edited on
The input you give the program is confusing. Can you seperate your inputs from output, put them on separate lines? Most of the output you are showing is not even in the code you posted. Also where is main?
Don't ever user goto. Ever.
By "inputs i give the program" your talking about the text file i assume.

"1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2 <---end of text output

8 <---takes inputs

i <---correct answer that '8' gets

7<---clears the screen

3<---compares inputs '8' gets

4 You continue on picking up speed to get to the egg first.. and.. Oh No, You accidentally bumped into the walls! 2 <---text output based on '3'

5 1 You go over, and as you realize the walls are acidic and thats why the other sperm are dieing.. 2 <---other text output based on '3'
6"<---makes a new line


Here is main, it is below this function and references it.
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
int main()
{
menu:
	system("cls");
	cout << "Welcome to Your Text Games\n\n\n";
	int option;
	do
	{	
		cout << "1) Load a New Game\n\n";
		cout << "2) Instructions\n\n";
		cout << "3) Exit\n\n";
		cout << "Please Select an Option(number): ";
		cin >> option;
		

		if(option == 1) //make a new game
		{
		progfiles();
		}
		if(option == 2) //load a new game
		{
		system("cls");
		cout << "Welcome, If you would like to make a custom game follow these instructions exactly, it would also be beneficial to play through the game included to get an idea of what you can do.\n\n\n";
		cout << "First you need to know the what the 'flags' are, they stand for functions that tell the program what should happend in the game at that point in time.\n\n";
		cout << "These are the flags that control the game you will make:\n" << "1-tells the program the following is text for display\n" << "2-tells the program to stop displaying the following text(must be preceded by 1)";
		cout << "3-tells the program to compare a deignated answer with a user input(must come after flag 8 and a character for a choice)\n" << "4-tells the program the follwoing is a negative(wrong answer) message(followed by 2 to end the text)\n";
		cout << "5-tells the program the follwing is a positive(right answer) message(followed by 1 and text ends by 2)\n" << "6-tells the program to go to a new line\n" << "7-tells the program to clear the screen\n";
		cout << "8-tells the program to get user input(for a choice) and the correct choice from a file\n" << "9-closes the file(must be the last flag in the program, and cannot be followed by anything)\n";
		system("pause");
		cout << "\n\n\n\n\n\n";
		cout << "A copy of these Flags can be found in the desktop file you created on instilation.\n" << "The game files are just text files, with text and flags in them.\n" << "Because of the way the program works everything includeing flags must be typed with spaces inbetween.\n";
		cout << "For example '1 Hello World, is your day good or bad?(g-good/b-bad) 2 8 g 7 3 4 Aww i'm sorry it was bad 5 1 Thats good! 2 6 6 9' shows how everything must be typed.\n";
		cout << "you can always open a different game text file to try to understand how it works, just dont change anything..\n";
		system("pause");
		system("cls");
		cout << "follow the rules for making the games exactly and nothing will go wrong, Have Fun creating!";
		}
		else //if none of the options are selected
		{
			system("pause");
			system("cls");
			goto menu;
		}
	}
	while(option != 3); //exit
	system("cls");
	system("pause");




	return 0;
}
Topic archived. No new replies allowed.