473,382 Members | 1,313 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Grade.cpp

I really need help I have got this program all screwed and cant figure out why I cant access my char grades pleade help C learner

Grade.cpp
Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char *argv[])
  2.    {
  3.  
  4.  
  5.  
  6. void inputRecord (StudentRecord record); 
  7. //postcondition 
  8. void computeAverage (StudentRecord& record);
  9. //precondition
  10. char letterGrade (double numericGrade);
  11. //precondition
  12. void outputRecord (StudentRecord record);
  13. //precondition
  14.   //stream insertion operators were reversed for cout and cin functions
  15.  
  16. StudentRecord record;
  17.    cout << "Please Enter Your Grades Below" << endl << "Quiz One: ";
  18.    cin >> record.quiz1;
  19.    cout <<  "Quiz Two: ";
  20.    cin >>  record.quiz2;
  21.    cout << endl;
  22.    cout << "Midterm Exam Score: ";
  23.    cin >>  record.midtermExam;
  24.    cout << endl;
  25.    cout << "Final Exam Score: ";
  26.    cin >>  record.finalExam;
  27.    cout << endl;
  28.  
  29.  
  30.  
  31. }
  32.  
  33. void computeAverage (StudentRecord& record)
  34. {
  35.   const double EXAM_WT = 0.5;
  36.   const double MIDTERM_WT = 0.25;
  37.   const double QUIZ_WT = 0.25;
  38.   double quiz1Percent, quiz2Percent;
  39.  
  40.   //
  41.   // Convert the 10 point quizzes to a percent, then find the average
  42.   //
  43.   quiz1Percent = 100 * record.quiz1 / 10.0;
  44.   quiz2Percent = 100 * record.quiz2 / 10.0;
  45.   double quizAvg = (quiz1Percent + quiz2Percent) / 2;
  46.  
  47.   //
  48.   // Compute the weighted average to get the numeric course grade
  49.   // 
  50.   record.courseAverage = quizAvg * QUIZ_WT + record.midtermExam * MIDTERM_WT + 
  51.   record.finalExam * EXAM_WT;
  52.  
  53.   //
  54.   // Call the letterGrade function to find the corresponding letter grade
  55.   record.letterGrade = letterGrade (record.courseAverage);
  56.  
  57. exit(1);
  58.     }
Nov 5 '07 #1
11 3683
scruggsy
147 100+
Your functions look fine for the most part.
Weird that you have your function prototypes in main, though.
Can you explain the problem more clearly?
You go to all the trouble of inputting the grades in main, but you never call any of your functions to calculate the average and determine the letter grade.
Nov 5 '07 #2
The problem I have is getting the char grades
heres what i came with after I posted

It seems like none of the previous fuctions if initialized I dont get I am getting really frustrated


removed full code
Nov 5 '07 #3
Studlyami
464 Expert 256MB
You go to all the trouble of inputting the grades in main, but you never call any of your functions to calculate the average and determine the letter grade.
First PLEASE use the code tags when posting code. Second you never call your functions! Also, your letter grade function prototype says it takes receives an int, but the actual function definition you say it receives a double.
Nov 6 '07 #4
First PLEASE use the code tags when posting code. Second you never call your functions! Also, your letter grade function prototype says it takes receives an int, but the actual function definition you say it receives a double.


Yea I see the int char but the problem I am having is calling the grades or the letter grade I know i am missing something but I cant get it eventually I will after i tear it completely up and try again[/code]
Nov 6 '07 #5
well so far I have gotten this far I have the input and output working but my char function still doesnt please help I am pulling my hair out here

#include "stdafx.h"
#include <iostream>
#include <math.h>
using namespace std;


//
// Structure for a student record
//


struct StudentRecord
{
double quiz1;
double quiz2;
double midtermExam;
double finalExam;
double courseAverage;
char letterGrade;

};

int main()
{


StudentRecord record;
cout << "Please Enter Your Grades Below" << endl << "Quiz One: ";
cin >> record.quiz1;
cout << "Quiz Two: ";
cin >> record.quiz2;
cout << endl;
cout << "Midterm Exam Score: ";
cin >> record.midtermExam;
cout << endl;
cout << "Final Exam Score: ";
cin >> record.finalExam;
cout << endl;
cout << "Quiz Scores: " << record.quiz1 << " " << record.quiz2 << endl;
cout << "Midterm Exam Score: " << record.midtermExam << endl;
cout << "Final Exam Score: " << record.finalExam << endl;
cout << endl;
cout << "Course Average: " << record.courseAverage << endl;
cout << "Final Letter Grade: " << record.letterGrade << endl;
cout << endl;
}

char letterGrade (double numericGrade)
{
char letter;

if (numericGrade < 60)
letter = 'F';
else if (numericGrade < 70)
letter = 'D';
else if (numericGrade < 80)
letter = 'C';
else if (numericGrade < 90)
letter = 'B';
else
letter = 'A';

return letter;
}


void computeAverage (StudentRecord& record)
{
const double EXAM_WT = 0.5;
const double MIDTERM_WT = 0.25;
const double QUIZ_WT = 0.25;
double quiz1Percent, quiz2Percent;

//
// Convert the 10 point quizzes to a percent, then find the average
//
quiz1Percent = 100 * record.quiz1 / 10.0;
quiz2Percent = 100 * record.quiz2 / 10.0;
double quizAvg = (quiz1Percent + quiz2Percent) / 2;

//
// Compute the weighted average to get the numeric course grade
//
record.courseAverage = quizAvg * QUIZ_WT + record.midtermExam * MIDTERM_WT +
record.finalExam * EXAM_WT;

//
// Call the letterGrade function to find the corresponding letter grade
record.letterGrade = letterGrade (record.courseAverage);

exit(1);

}
Nov 6 '07 #6
scruggsy
147 100+
the problem I am having is calling the grades or the letter grade I know i am missing something but I cant get it
You don't call letterGrade(). There's a call to it in computeAverage(), but you never call that function.
Are you unsure how to call that function, or is there some compiler error, or what?
BTW, why the exit(1) at the end of computeAverage()? Surely you don't want to terminate your program at the end of that function...
Nov 6 '07 #7
oler1s
671 Expert 512MB
After 4 posts, you should have somehow found about the CODE tags. We'll wait until you fix your post to use these CODE tags. If somehow, you are not familiar with CODE tags, then it's simply putting [CODE ] and [/ CODE] tags around your code.

Because unformatted code is unreadable, and attempting to read poorly formatted code leads to mistakes on our part, we'll wait until you make the appropriate correction.

I notice a few points right away, but only because they stand out so much. <math.h> should be <cmath> . If you do not know why, ask.

You're use of exit(1) in computeAverage is puzzling. I'd like you to explain why it's there.

In main(), there are no calls to your function computeAverage. Obviously, computeAverage won't run unless it is called. Therefore, call the function appropriately...

EDIT: You have another ongoing thread dealing with this question. Starting multiple threads is more than rude. It means that you start multiple threads of advice, with people not knowing what the other threads have discovered. You are wasting people's time this way. Perhaps a mod will merge your thread. I hope you have more concern for internet etiquette in the future.
Nov 6 '07 #8
scruggsy
147 100+
I won't berate you further, although everything oler1s pointed out is valid.
I think you're not understanding how functions work on a basic level.
A program terminates as soon as it hits the closing brace of main().
The way your code is laid out, it almost seems that you think execution will continue past main(), into letterGrade() and finally ending up in computeAverage(), terminating with exit(1) in that function.
That is not how it works.

Example of calling functions:
Expand|Select|Wrap|Line Numbers
  1. void doSomething()
  2. {
  3.   //do stuff
  4. }
  5.  
  6. int main(){     // <- Execution begins here
  7.   doSomething();
  8.   doSomethingElse();
  9.   return 0;   // or exit(1) if you must
  10. }                 // <- Execution ends here
  11.  
  12. void doSomethingElse()
  13. {
  14.   //do other stuff
  15. }
Notice that although doSomething() is defined above main, and doSomethingElse() below it, neither function runs until it is called by main(). After the program reaches the closing brace of either function (or hits a return in that function), execution passes back to main().
Sorry if this is old news to you; I'm just trying to help in the absence of a better explanation of the problem.
Nov 6 '07 #9
I won't berate you further, although everything oler1s pointed out is valid.
I think you're not understanding how functions work on a basic level.
A program terminates as soon as it hits the closing brace of main().
The way your code is laid out, it almost seems that you think execution will continue past main(), into letterGrade() and finally ending up in computeAverage(), terminating with exit(1) in that function.
That is not how it works.

Example of calling functions:
Expand|Select|Wrap|Line Numbers
  1. void doSomething()
  2. {
  3.   //do stuff
  4. }
  5.  
  6. int main(){     // <- Execution begins here
  7.   doSomething();
  8.   doSomethingElse();
  9.   return 0;   // or exit(1) if you must
  10. }                 // <- Execution ends here
  11.  
  12. void doSomethingElse()
  13. {
  14.   //do other stuff
  15. }
Notice that although doSomething() is defined above main, and doSomethingElse() below it, neither function runs until it is called by main(). After the program reaches the closing brace of either function (or hits a return in that function), execution passes back to main().
Sorry if this is old news to you; I'm just trying to help in the absence of a better explanation of the problem.
isn't it against the rules to post complete code from a student assignment? Your in CSCI7 at COS, rigt?
Nov 6 '07 #10
isn't it against the rules to post complete code from a student assignment? Your in CSCI7 at COS, rigt?

2rong! And No Im not part of a student assignment if i was part of an assignment and I had an instructor I wouldn't be asking another newbe for help on a fuction call, You know when people come to these forums its for help on topics they ask about but instead of help they get its just plain put downs and oh my God he's an idiot cause he's calling a function the wrong way.
If the person who is replying to the forum doesnt want to help the person asking then why reply in the first place?
Nov 7 '07 #11
sicarie
4,677 Expert Mod 4TB
C Learner-

We get a surprising amount of requests for help with homework on topics much more simple than the one you are working on. I do believe jpenguin was referencing this site's Posting Guidelines - that we are not supposed to allow full code to be posted - and he recognized the assignment (which happens to be a common one throughout universities).

jpenguin & C Learner -
As I don't believe jpenguin said anything about C Learner's coding ability, due to the direction this thread is going, I will ask the both of you to read the Posting Guidelines because if any flames (disparaging comments) are found in this thread (or in any thread in any forum), those who have posted inappropriately will be reprimanded, possibly even banned.

PS - C Learner, please check your Private Messages accessible through the PM link in the top right corner of this page. Thanks.
Nov 7 '07 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

35
by: Henry | last post by:
I was doing this program for an exercise in a book. The point was to create a program that would take a numerical grade from a user and convert it to a letter grade (yeah really easy). I tried to...
1
by: sparkid | last post by:
I need immediate help in writing a function program. I have to write a program in functions and use array to store them. I am not familiar with functions and i tried to create it but i fails to...
7
by: tea-jay | last post by:
hello every body our teacher asks us to write this assiment it has 2 question i did write the first one but the other was really complicated 2 me coz our teacher doesn't know how to explain...
4
by: Madmartigan | last post by:
Hello I have attempted the source code from Chapter 4 in Accelerated C++ page 70 but keep getting the above error. I'm not sure whether it is in the way I have saved the header files or because my...
2
by: yalbizu | last post by:
#include <iostream> #include <string> #include <fstream> #include <iomanip> using namespace std; const int NO_OF_STUDENTS=20; struct studentType { string studentFName; string studentLName;
1
by: mercea | last post by:
Hi all, i have a web page which contains a gridview. On this gridview, the user uses a set of radiobuttonlists to select an option. the selected option is then to be compared with the data in a...
3
by: hanie | last post by:
a student wants to know his grade average for the semester. the grades are give in letter grades with numeric equivalents. develop a solution to calculate a grade average given the letter grades(the...
3
by: blamp | last post by:
I have completed most of the program I just cant get the letter grade to print from the void printGrade function.The output of the program should be: Line 1: Based on the course score, this...
9
tiktik
by: tiktik | last post by:
Hi... I am doing this simple Java program which displays a particular grade (A, B, C...) according to the mark entered. However I cannot arrange it in such a way that it displays "Invalid" if...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.