S
Simon Gibson
Hi there, im trying to write a program where you can write reports and save
them into an array. im having problems with getting the string into an array
tho it seems to be skipping over the cin.getline function entiryly and going
back upto the start of the menu. the problem seems to lie with '\n' bit if i
change that to say 'a' it will run fine but accept a as ending the input.
any help getting the '\n' working is appreciated!!
heres the code:
//---------------------------------------------
//program to store match reports into an array and view them
//
//
//---------------------------------------------
#include <iostream>
using namespace std;
int main()
{
const int MAX = 600;
char matches[10][MAX]; //array declaration
int choice = 0; //number choice
int count = 0; //array location count
int i = 0; //I initialised here cos cant in
case??
while (choice != 3)
{
cout << "Welcome to the match database"; //menu.
cout << endl
<< "1. View Entrys"
<< endl
<< "2. Add Entry"
<< endl
<< "3. End program"
<< endl
<< "please choose an option: ";
cin >> choice;
switch(choice) //choice selection
{
case 1: //view entrys
for(i = 0;i < count; i++) //reset i to view full list
each time
{
cout << endl
<< "Match report number: " << i
<< endl
<< *(matches+i); //view matches.
}
break;
case 2: // add entry
cout << endl // Prompt for input
<< "Enter Your Report. it must be less than "
<< MAX << " characters:"
<< endl;
cin.getline ( matches[count], MAX, '\n'); // add to array
count++; //inc count
break;
case 3: //quit program
return 0;
break;
default:
cout << endl
<< "not a valid number "
<< endl;
}
}
return 0;
}
them into an array. im having problems with getting the string into an array
tho it seems to be skipping over the cin.getline function entiryly and going
back upto the start of the menu. the problem seems to lie with '\n' bit if i
change that to say 'a' it will run fine but accept a as ending the input.
any help getting the '\n' working is appreciated!!
heres the code:
//---------------------------------------------
//program to store match reports into an array and view them
//
//
//---------------------------------------------
#include <iostream>
using namespace std;
int main()
{
const int MAX = 600;
char matches[10][MAX]; //array declaration
int choice = 0; //number choice
int count = 0; //array location count
int i = 0; //I initialised here cos cant in
case??
while (choice != 3)
{
cout << "Welcome to the match database"; //menu.
cout << endl
<< "1. View Entrys"
<< endl
<< "2. Add Entry"
<< endl
<< "3. End program"
<< endl
<< "please choose an option: ";
cin >> choice;
switch(choice) //choice selection
{
case 1: //view entrys
for(i = 0;i < count; i++) //reset i to view full list
each time
{
cout << endl
<< "Match report number: " << i
<< endl
<< *(matches+i); //view matches.
}
break;
case 2: // add entry
cout << endl // Prompt for input
<< "Enter Your Report. it must be less than "
<< MAX << " characters:"
<< endl;
cin.getline ( matches[count], MAX, '\n'); // add to array
count++; //inc count
break;
case 3: //quit program
return 0;
break;
default:
cout << endl
<< "not a valid number "
<< endl;
}
}
return 0;
}