Need advise on looping!

I'm new in programming and I've been working on this program for our class but I can get the loop to work. I have been looking for answers but I can find any on the net. The first line is the only one that doesn't work.


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

struct student_course{
char fname[30];
char lname[30];
char mname[30];
char course[30];
char section[20];
int age;
}csdp,csnt,bios,wad;

void Student_Course()
{
ofstream student_input;
student_input.open("Student Data.txt",ios::app);
cout<<"First Name:";
cin.getline (csdp.fname,30);
student_input<<"First Name:";
student_input<<csdp.fname<<endl;
cout<<"Last Name:";
cin.getline (csdp.lname,30);
student_input<<"Last Name:";
student_input<<csdp.lname<<endl;
cout<<"Middle Name:";
cin.getline (csdp.mname,30);
student_input<<"Middle Name:";
student_input<<csdp.mname<<endl;
cout<<"Course:";
cin.getline (csdp.course,30);
student_input<<"Course:";
student_input<<csdp.course<<endl;
cout<<"Section:";
cin.getline (csdp.section,20);
student_input<<"Section:";
student_input<<csdp.section<<endl;
cout<<"Age:";
cin>>csdp.age;
student_input<<"Age:";
student_input<<csdp.age<<endl<<endl;
student_input.close();
}

void Output_Choice()
{
char choice1,ch;
cout<<"Do you  want to see the output?(y/n):";
cin>>choice1;
if (choice1=='y'||choice1=='Y'){
system ("cls");
ifstream student_input;
student_input.open ("Student Data.txt");
while (!student_input.eof())
{
student_input.get(ch);
cout<<ch;
}
student_input.close();
}else if (choice1=='n'||choice1=='N'){
cout<<"Thank you for using this program."<<endl;
}
}

int main()
{
char choice0;
Student_Course();
cout<<"Try again?(y/n):";
cin>>choice0;

if (choice0=='y'||choice0=='Y'){
system ("cls");
Student_Course();
}else if (choice0=='n'||choice0=='N'){
system ("cls");
Output_Choice();
}

system ("pause");
return 0;
}


Thank for the help!!!
Last edited on
Please edit your post and put the source inside code tags. It will make your post a lot more legible and folks here will be more likely to look at it.
Topic archived. No new replies allowed.