Printing contents of an input file to the screen
Nov 24, 2009 at 3:43pm UTC
My program is supposed to read from this output file and print the contents to the screen NOTHING IS BEING PRINTED:
CPTR151‐01
000143 Doe John Q 10 5
000143 Doe John Q 10 7
000143 Doe John Q 10 9
000143 Doe John P 20 17
000143 Doe John P 20 15
000143 Doe John M 50 45
000143 Doe John F 50 40
991253 Dough Jane Q 10 10
991253 Dough Jane Q 10 6
991253 Dough Jane Q 10 2
991253 Dough Jane P 20 20
991253 Dough Jane P 20 7
991253 Dough Jane M 50 35
991253 Dough Jane F 50 47.5
I have a read until end of file command and all the necessary other commands.
I read in the first id number as Student_id and then if the id is not equal to the new id read in then it calculated the grades for the student and outputs it to the screen and then continues to read the rest of the data entered.
This is what I have for that section of code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
myfile>>New_id;
if (Student_id!=New_id)
{
quiz.Average=quiz.Tot_Ach/quiz.Tot_Poss;
prog.Average=prog.Tot_Ach/prog.Tot_Poss;
Poss_Score= quiz.Tot_Poss+prog.Tot_Poss+mid.Tot_Poss+fin.Tot_Poss;
Acheived_Score=quiz.Tot_Ach+prog.Tot_Ach+mid.Tot_Ach+fin.Tot_Ach;
Per=(Acheived_Score/Poss_Score)*100/1;
cout<<Firstname<<" " <<Lastname<<endl;
cout<<"Quiz Average: " <<quiz.Average<<endl;
cout<<"Programming Average: " <<prog.Average<<endl;
cout<<"Final Percentage: " <<Per;
}
}
return 0;
}
}
This is all of my code just in case
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
#include<iostream>
#include<string>
#include<fstream>
using namespace std;
struct Type
{
double Poss_Score;
double Acheived_Score;
double Tot_Poss;
double Tot_Ach;
double Average;
}quiz,prog,mid,fin;
int main()
{
string Course_Name;
int Student_id;
int New_id;
string Lastname;
string Firstname;
char Assignment_Type;
double Poss_Score;
double Acheived_Score;
double Per;
//Section 1- This section reads the information from the input file and assigns appropriate variable names.
ifstream myfile;
myfile.open("student_info.dat" );
while (!myfile.eof())
{
getline(myfile,Course_Name);
myfile>>Student_id;
myfile.get();
myfile>>Lastname;
myfile.get();
myfile>>Firstname;
myfile.get();
myfile>>Assignment_Type;
switch (Assignment_Type)
{
case 'Q' :
myfile>>quiz.Poss_Score>>quiz.Acheived_Score;
quiz.Tot_Poss+=quiz.Tot_Poss;
quiz.Tot_Ach+=quiz.Tot_Ach;
break ;
case 'P' :
myfile>>prog.Poss_Score>>prog.Acheived_Score;
prog.Tot_Poss+=prog.Poss_Score;
prog.Tot_Ach+=prog.Tot_Ach;
break ;
case 'M' :
myfile>>mid.Poss_Score>>mid.Acheived_Score;
mid.Tot_Poss+=mid.Poss_Score;
mid.Tot_Ach+=mid.Acheived_Score;
break ;
case 'F' :
while (!myfile.eof())
{
getline(myfile,Course_Name);
myfile>>Student_id;
myfile.get();
myfile>>Lastname;
myfile.get();
myfile>>Firstname;
myfile.get();
myfile>>Assignment_Type;
switch (Assignment_Type)
{
case 'Q' :
myfile>>quiz.Poss_Score>>quiz.Acheived_Score;
quiz.Tot_Poss+=quiz.Tot_Poss;
quiz.Tot_Ach+=quiz.Tot_Ach;
break ;
case 'P' :
myfile>>prog.Poss_Score>>prog.Acheived_Score;
prog.Tot_Poss+=prog.Poss_Score;
prog.Tot_Ach+=prog.Tot_Ach;
break ;
case 'M' :
myfile>>mid.Poss_Score>>mid.Acheived_Score;
mid.Tot_Poss+=mid.Poss_Score;
mid.Tot_Ach+=mid.Acheived_Score;
break ;
case 'F' :
myfile>>fin.Poss_Score>>fin.Acheived_Score;
myfile>>fin.Poss_Score>>fin.Acheived_Score;
fin.Tot_Poss+=fin.Poss_Score;
fin.Tot_Ach+=fin.Acheived_Score;
break ;
default :cout<<"Invald Input" ;
}
}
myfile>>New_id;
if (Student_id!=New_id)
{
quiz.Average=quiz.Tot_Ach/quiz.Tot_Poss;
prog.Average=prog.Tot_Ach/prog.Tot_Poss;
Poss_Score= quiz.Tot_Poss+prog.Tot_Poss+mid.Tot_Poss+fin.Tot_Poss;
Acheived_Score=quiz.Tot_Ach+prog.Tot_Ach+mid.Tot_Ach+fin.Tot_Ach;
Per=(Acheived_Score/Poss_Score)*100/1;
cout<<Firstname<<" " <<Lastname<<endl;
cout<<"Quiz Average: " <<quiz.Average<<endl;
cout<<"Programming Average: " <<prog.Average<<endl;
cout<<"Final Percentage: " <<Per;
}
}
return 0;
}
}
Last edited on Nov 24, 2009 at 4:18pm UTC
Nov 24, 2009 at 4:10pm UTC
What is the problem? And don't double post please.
Nov 24, 2009 at 4:37pm UTC
The problem is that the output wont print to the screen. When compiled the program doesnt have any errors it's just that it wont output to the screen.
Topic archived. No new replies allowed.