Click here to Skip to main content
15,887,135 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Loading DLL from file not PATH Pin
Richard MacCutchan16-Jun-22 0:01
mveRichard MacCutchan16-Jun-22 0:01 
GeneralRe: Loading DLL from file not PATH Pin
Valentinor16-Jun-22 0:37
Valentinor16-Jun-22 0:37 
GeneralRe: Loading DLL from file not PATH Pin
Richard MacCutchan16-Jun-22 2:08
mveRichard MacCutchan16-Jun-22 2:08 
GeneralRe: Loading DLL from file not PATH Pin
Richard MacCutchan16-Jun-22 5:22
mveRichard MacCutchan16-Jun-22 5:22 
GeneralRe: Loading DLL from file not PATH Pin
Valentinor16-Jun-22 6:06
Valentinor16-Jun-22 6:06 
QuestionMeasure ITEM ITEMDATA string coming in as Wide Character string Pin
ForNow6-Jun-22 17:28
ForNow6-Jun-22 17:28 
AnswerRe: Measure ITEM ITEMDATA string coming in as Wide Character string Pin
Richard MacCutchan6-Jun-22 21:01
mveRichard MacCutchan6-Jun-22 21:01 
QuestionGrades Pin
Stephanie Foley6-Jun-22 7:38
Stephanie Foley6-Jun-22 7:38 
Use an input file

An instructor has asked you to write a program that can tell him if his students have passed or
failed his course. He has a file that contains the following information:
• first name
• last name
• five quiz grades
• the midterm exam grade
• the final exam grade
Your program must read these values into variables then use those variables to calculate the
final average and finally display that average to the screen.
Requirements:
1. All input comes from a file – grades.txt. You may NOT ask for input from the professor. This
file is posted on Canvas for your program to use.
2. Remember: Your program must calculate the final average including those quizzes. All the
quizzes averaged together count as much as a test. So, to calculate the final, you need to
calculate the quiz average first, then average the midterm + final + quiz average.
3. Display the student’s last name first, comma, space and first name. Follow that with the final
average as a whole number, rounded up
The file contains one line of data in the following order:
firstName lastName q1 q2 q3 q4 q5 midterm final
Remember, data must be read in sequentially! This means that the first name variable must be
initialized before the last name or the quiz one and etc.

Code:
#include <iostream>
#include <fstream>
using namespace std;

/* run this prgram using the console pauser or add your own getch, system('pause") or input look */
int main(int argc, char** argv)
{
string firstName,lastName;
int q1, q2, q3, q4, q5, midterm, final;
int quizaverage;
int average;

ifstream inFile;
inFile.open("grades.txt");

inFile>>firstName>>lastName>>q1>>q2>>q3>>q4>>q5>>midterm>>final;


//Calculate the quiz average.
quizaverage=(q1+q2+q3+q4+q5)/5;

average=(quizaverage+midterm+final)/3*100;

cout<<"Dobbs, Bob"<<" Average: "<<average;

inFile.close();
return 0;

I need help with this. I am trying to use the numbers given from a text file in the program.
AnswerRe: Grades Pin
Richard MacCutchan6-Jun-22 9:08
mveRichard MacCutchan6-Jun-22 9:08 
GeneralRe: Grades Pin
Stephanie Foley6-Jun-22 10:03
Stephanie Foley6-Jun-22 10:03 
GeneralRe: Grades Pin
Richard MacCutchan6-Jun-22 10:19
mveRichard MacCutchan6-Jun-22 10:19 
GeneralRe: Grades Pin
jeron16-Jun-22 11:29
jeron16-Jun-22 11:29 
Questionreference question Pin
focusdoit5-Jun-22 12:50
focusdoit5-Jun-22 12:50 
AnswerRe: reference question Pin
k50545-Jun-22 13:26
mvek50545-Jun-22 13:26 
AnswerRe: reference question Pin
Richard MacCutchan6-Jun-22 0:52
mveRichard MacCutchan6-Jun-22 0:52 
Questionmath Pin
Calin Negru4-Jun-22 20:13
Calin Negru4-Jun-22 20:13 
AnswerRe: math Pin
Victor Nijegorodov4-Jun-22 20:42
Victor Nijegorodov4-Jun-22 20:42 
AnswerRe: math Pin
Richard MacCutchan4-Jun-22 21:10
mveRichard MacCutchan4-Jun-22 21:10 
GeneralRe: math Pin
Calin Negru4-Jun-22 22:03
Calin Negru4-Jun-22 22:03 
GeneralRe: math Pin
Richard MacCutchan4-Jun-22 22:10
mveRichard MacCutchan4-Jun-22 22:10 
GeneralRe: math Pin
Calin Negru4-Jun-22 23:04
Calin Negru4-Jun-22 23:04 
QuestionGame loop and time measurement. Pin
Member 152127684-Jun-22 5:23
Member 152127684-Jun-22 5:23 
AnswerRe: Game loop and time measurement. Pin
Mircea Neacsu4-Jun-22 7:47
Mircea Neacsu4-Jun-22 7:47 
AnswerRe: Game loop and time measurement. Pin
Calin Negru4-Jun-22 10:43
Calin Negru4-Jun-22 10:43 
QuestionCollege Project Visual Enhancement Pin
Tomás Temperley2-Jun-22 15:31
Tomás Temperley2-Jun-22 15:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.