View Single Post
Old 04-14-2005, 07:38 AM   #1 (permalink)
mconn86
Registered User
 
Join Date: Apr 2005
Posts: 5
mconn86 is on a distinguished road
cin.getline problems

hi, im relativly new to C++, im just starting to write a simple program where i get the user to read in a string of characters.Im keeping it very simple at first so I can modify it later to use in my program, where I'm having problems is when I ask the user if they want to try again, the computer still holds the value of the original array in its memory and this causes the whole program to go a bit crazy. I think i should be using a cin.ignore statement or something like that but im not too sure how. You can view my program below (very basic,just want to get my head around the idea). Nyone out there with any advice,cheers!
Code:
#include <iostream.h>

main_program();

int main()
{

main_program();

return 0;
}

main program()
{
char code[14];
char reply;

cout << "Please enter your code" << endl;
cin.getline (code,14);
cout << code << endl;
cout << "Go again?" << endl;
cin >> reply;
 if (reply =='y')
    {
     main_program();
     }
return 0;
}

Last edited by Valmont; 04-14-2005 at 09:55 AM.
mconn86 is offline   Reply With Quote