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.