Cannot enter string

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();
}


first_check.cpp
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
#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();
  }
}


check_steam.cpp
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
#include "header.h"

int check_steam()
{
    char check_steam = 'a';
    
    cout << "\n\nWelcome to the Republic Commando Map List Updater V2.6";
    cout << "\n\nPlease answer the following questions for a first time set up.";

    cout << "\n\n\n1.  Do you own a Steam copy of the game? <y or n>";
    cout << "\n > ";
    cin >> check_steam;
    
    if (check_steam != 'y')
    {
      if (check_steam != 'n')
      {
      cout << "That is not a valid answer.  Please try again.";
      check_steam;
      }
    }
    if (check_steam == 'y')
    {
      ofstream myfile;
      myfile.open ("config.mlu", ios::out | ios::app);
      myfile << "yes\n";
      myfile.close();
      default_path = "C:\\Program Files\\Steam\\steamapps\\common\\Star Wars Republic Commando\\";
    }
    if (check_steam == 'n')
    {
      ofstream myfile;
      myfile.open ("config.mlu", ios::out | ios::app);
      myfile << "no\n";
      myfile.close();
      default_path = "C:\\Program Files\\LucasArts\\Star Wars Republic Commando\\";
    }
}


normal.cpp (Probably insignificant but you never know)
1
2
3
4
5
6
#include "header.h"

int normal()
{
    cout << "Config Complete";
}


header.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include <iostream>
#include <fstream>
#include <string>
#include <sys/stat.h> 

using namespace std;

//The Modules
int first_check();
int normal();
int check_steam();

//Global Variables
extern string default_path;



I fully appreciate this and thank you in advance. (I know you have better things to do :P)

Timbo1
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
      }
    }



Thanks I will change that to a while loop but there is no cin there as it runs the check_steam file from the start again.
Anyone???
well, don't name a variable like the enclosing function.

check_steam.cpp, line 19 should be check_steam();

what do you mean with
Timbo1 wrote:
third gets skipped
What? Where?
1
2
3
4
5
6
7
8
9
10
11
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:

 
getline(cin, default_path);
that is because cin >> check_path; does not remove the '\n' from the stream.You need to write cin.ignore(/*like*/100, '\n'); after that line
Now I am getting a ton of linker errors saying I have undefined references to default_path.

I tried taking out the cin.ignore code but they are still there.

I don't think I've changed anything else.
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.
Thank you very much,

All is well and I can now progress.

Thank you
Topic archived. No new replies allowed.