dubstar
format c:
- Joined
- 3 Dec 2002
- Messages
- 1,357
i'm pulling information from a file -- in this order -- first name, last name, scores (different amount of scores for each line).
example:
john doe 44 100 80 33 -1
jane johnson 33 -4
hooka smoker -9
etc etc 0 44 99 -44
the negative score is supposed to tell the code to stop, read it, but stop that line and move to the next line.
problem code:
or
here is the whole function code:
i've tried this tons of different ways but cant seem to find one that works properly. eventually i have to put this in to an array, having fname and lname the arrays.. but if i dont understand the first parts, i'm not ready to put it into an array.
example:
john doe 44 100 80 33 -1
jane johnson 33 -4
hooka smoker -9
etc etc 0 44 99 -44
the negative score is supposed to tell the code to stop, read it, but stop that line and move to the next line.
problem code:
Code:
[SIZE=2]in >> score;[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2] (score >= 0)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]cout << score;[/SIZE]
[SIZE=2]}[/SIZE]
or
Code:
[SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i=0;i<10;i++)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]in >> score[i + 0];[/SIZE]
[SIZE=2]cout << score[i + 0];[/SIZE]
[SIZE=2]}[/SIZE]
here is the whole function code:
Code:
[SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][SIZE=2] ReadRecord()[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]ifstream in; [/SIZE][SIZE=2][COLOR=#008000]// input file[/COLOR][/SIZE]
[SIZE=2]string fname; [/SIZE][SIZE=2][COLOR=#008000]// first name[/COLOR][/SIZE]
[SIZE=2]string lname; [/SIZE][SIZE=2][COLOR=#008000]// last name[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] score;[/SIZE]
[SIZE=2][COLOR=#008000]//OPEN FILES[/COLOR][/SIZE]
[SIZE=2]in.open([/SIZE][SIZE=2][COLOR=#a31515]"c:\\in_infoproc.txt"[/COLOR][/SIZE][SIZE=2], ios::in); [/SIZE][SIZE=2][COLOR=#008000]// opens in.txt file for input[/COLOR][/SIZE]
[SIZE=2][COLOR=#008000]//READ RECORD[/COLOR][/SIZE]
[SIZE=2]ql_header(); [/SIZE][SIZE=2][COLOR=#008000]// program header (includes clear screen)[/COLOR][/SIZE]
[SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515]"\n\n\n\n\t\tRead Records\n\n\n"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2] (in.eof() == [/SIZE][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][SIZE=2])[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]getline(in, fname, [/SIZE][SIZE=2][COLOR=#a31515]' '[/COLOR][/SIZE][SIZE=2]); [/SIZE][SIZE=2][COLOR=#008000]// first name[/COLOR][/SIZE]
[SIZE=2]getline(in, lname, [/SIZE][SIZE=2][COLOR=#a31515]' '[/COLOR][/SIZE][SIZE=2]); [/SIZE][SIZE=2][COLOR=#008000]// last name[/COLOR][/SIZE]
[SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515]"\t\tYour name is:\t"[/COLOR][/SIZE][SIZE=2] << fname << [/SIZE][SIZE=2][COLOR=#a31515]" "[/COLOR][/SIZE][SIZE=2] << lname << endl;[/SIZE]
[SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515]"\t\tYour score is:\t"[/COLOR][/SIZE][SIZE=2];[/SIZE]
[SIZE=2]in >> score;[/SIZE]
[SIZE=2][COLOR=#0000ff]while[/COLOR][/SIZE][SIZE=2] (score >= 0)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]cout << score;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#0000ff]for[/COLOR][/SIZE][SIZE=2] ([/SIZE][SIZE=2][COLOR=#0000ff]int[/COLOR][/SIZE][SIZE=2] i=0;i<10;i++)[/SIZE]
[SIZE=2]{[/SIZE]
[SIZE=2]in >> score[i + 0];[/SIZE]
[SIZE=2]cout << score[i + 0];[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2]cout << [/SIZE][SIZE=2][COLOR=#a31515]"\n\t\t==============================================\n\n"[/COLOR][/SIZE][SIZE=2] << endl;[/SIZE]
[SIZE=2]}[/SIZE]
[SIZE=2][COLOR=#008000]//CLOSE FILES[/COLOR][/SIZE]
[SIZE=2]in.close();[/SIZE]
[SIZE=2][COLOR=#008000]//RETURN TO MENU[/COLOR][/SIZE]
[SIZE=2]Menu(0);[/SIZE]
[SIZE=2][COLOR=#008000]// ----------------------------------------------------------------------------------------------------------- END READ RECORD FUNCTION[/COLOR][/SIZE]
[SIZE=2]}[/SIZE]
i've tried this tons of different ways but cant seem to find one that works properly. eventually i have to put this in to an array, having fname and lname the arrays.. but if i dont understand the first parts, i'm not ready to put it into an array.
Last edited: