Hi there,
I am working on a program that updates a file based on user preferences.
All my code successfully compiles and I can enter two of the options but the third gets skipped all together and gives me no oppurtunity to enter an answer.
The variable in question is default_path which is used in first_check.cpp and check_steam.cpp. It has been declared externally in header.h
main.cpp
1 2 3 4 5 6 7 8
#include "header.h"
int main()
{
first_check(); //Run the config file check
cin.get();
}
#include "header.h"
int first_check()
{
//The Variables
char check_path = 'a';
//Check if configuration file is present
struct stat stFileInfo;
bool blnReturn;
int intStat;
// Attempt to get the file attributes
intStat = stat("config.mlu",&stFileInfo);
if(intStat == 0) {
blnReturn = true; //If it is, return true
} else {
blnReturn = false; //If not, return false
}
if(blnReturn == false) //If false ask configuration questions
{
check_steam();
cout << "\n\n\n2. Is this the installation path for your game. (THIS MUST BE CHECKED!!!) \n<y or n>";
cout << "\n";
cout << default_path;
cout << "\n > ";
cin >> check_path;
if (check_path == 'y')
{
ofstream myfile;
myfile.open ("config.mlu", ios::out | ios::app);
myfile << default_path;
myfile.close();
}
else
{
cout << "\n\n\n3. Please enter your game directory path. This must be right otherwise it will create unnecessary folders that can clutter and slow down your computer!";
cout << "\n > ";
getline(cin, default_path);
ofstream myfile;
myfile.open ("config.mlu", ios::out | ios::app);
myfile << default_path;
myfile.close();
}
cout << "\n\n\nThank you for completing this first time setup. You may now use the \nprogram freely!";
cin.get();
}
else //Else run the normal program
{
normal();
}
}
I havn't found the error you were talking about, but this part has an error ( i think ):
1 2 3 4 5 6 7 8 9 10
if (check_steam != 'y') //probably want to make this a while loop
//while (check_steam != 'y' || check_steam != 'n') perhaps?
{
if (check_steam != 'n')
{
cout << "That is not a valid answer. Please try again.";
check_steam; //----no cin here
}
}
else
{
cout << "\n\n\n3. Please enter your game directory path. This must be right otherwise it will create unnecessary folders that can clutter and slow down your computer!";
cout << "\n > ";
getline(cin, default_path);
ofstream myfile;
myfile.open ("config.mlu", ios::out | ios::app);
myfile << default_path;
myfile.close();
}
All the console outputs display but I get no option to enter the default path at:
writing extern string default_path; tells the compiler that default_path exists somewhere in your code. So you need to write string default_path; somewhere in your code otherwise the linker will wail.