Ask your own question, for FREE!
Computer Science 24 Online
OpenStudy (anonymous):

I am suppose to create a program to compute a students weighted course grade but I am not getting the results I want and the the program to display how I want it to. Below is the intstructions for the project along with how it is suppose to output when ran but when I debug my code and run it it does not compute the overall average how I want it. when I use the numbers given in the example to test the program it outputs an overall grade of 94.4 instead of the average 80.93. I also for some reason can't get the percent sign to show. I am missing a step but not sure where..I knwo that 101/150 is

OpenStudy (anonymous):

Write a program to compute a student's weighted course score. There are three tests in the class. The user should enter the maximum points for each test (they do not have to be the same) (integer), the student's score on each test (integer), and the weight of each test (as a percent of 1.0 (0.4 = 40%)) (floating-point value). Your code should output the student's weighted course grade. Example 1: Weight of first test: 30 Maximum on first test: 100 Score on first test: 93 Weight of second test: 30 Maximum on second test: 100 Score on second test: 87 Weight of third test: 40 Maximum on third test: 150 Score on third test: 101 Your overall grade is 80.93%

OpenStudy (anonymous):

my code #include <iostream> #include <string> using namespace std; int main() { int score1 = 0; int score2 = 0; int score3 = 0; int test1 = 0; int test2 = 0; int test3 = 0; double weight1 = 0; double weight2 = 0; double weight3 = 0; double weight = 0; cout << "Weight of first test:"; cin >> weight1; cout << "Maximum on first test:"; cin >> test1; cout << "score on first test:"; cin >> score1; cout << "Weight of second test:"; cin >> weight2; cout << "Maximum on second test:"; cout >> test2; cout << "Score on first test:"; cin >> score2; cout << "Weight of third test:"; cin >> weight3; cout << "Maximum on third test:"; cin >> test3; cout << "score3 on first test:"; cin >> score3; weight = score1* weight1 + score2 * weight2 + score3 * weight3; cout << " Your overall grade is " << weight << "\n"; system ("pause"); return 0; }

OpenStudy (anonymous):

not sure what I am not seeing or missing..

OpenStudy (ajprincess):

cout>>test2; it has to be cin>>test2;

OpenStudy (anonymous):

oh wow .. how did I not catch that

OpenStudy (anonymous):

ok when changed it still doe s not compute how I want it too.. am I missing an equation

OpenStudy (ajprincess):

ya. that's vat I am working on right nw:)

OpenStudy (anonymous):

You should probably divide the score of the test by the maximum score somewhere.

OpenStudy (anonymous):

so I would make intergeer for the equation lilke int score1= score1/test1?

OpenStudy (ajprincess):

(( score1* weight1)/test1)

OpenStudy (anonymous):

so it would be int double then

OpenStudy (anonymous):

For as far as I know `int double` doesn't exists. It'll be just `double`.

OpenStudy (ajprincess):

u have to divide the product of score and weight by the corresponding maximum score nd finding the sum of them gives u the desired output

OpenStudy (ajprincess):

Does that help? @RemyJDH

OpenStudy (anonymous):

yes that makes sense. I was in ball park but had it jerry rigged

OpenStudy (anonymous):

thank you for your assistance

OpenStudy (anonymous):

also quick question this has been baffling me. how do I create spaces between lines.. I know it something simple but I can t seem to remeber how to do it.

OpenStudy (ajprincess):

welcome:) for the percentage sign u can include it in the cout statement after weight

OpenStudy (anonymous):

Add "\n" to your string or use cout << endl;

OpenStudy (anonymous):

when I use the endl; or "\n" on my cout statement it does not output in format below Weight of first test: 30 Maximum on first test: 100 Score on first test: 93 Weight of second test: 30 Maximum on second test: 100 Score on second test: 87 Weight of third test: 40 Maximum on third test: 150 Score on third test: 101 Your overall grade is 80.93%

OpenStudy (anonymous):

Sorry, I probably misunderstood you. What output do you have right now?

OpenStudy (anonymous):

it spaces my input. so it ask the question and imy input will be under the sentence I can seem to create space between the the groups like when writing a new paragragh

OpenStudy (anonymous):

If I understand correctly, you have output something like this: Weight of the first test: 100 while your code is something like cout << "Weight of first test:\n"; cin >> weight1; If that's the case, you just need to replace the '\n' by a single space and it should be fine.

OpenStudy (anonymous):

let me see f that works

OpenStudy (anonymous):

I still get no spcae between the groups it out puts like this below Weight of first test: 30 Maximum on first test: 100 Score on first test: 93 Weight of second test: 30 Maximum on second test: 100 Score on second test: 87 Weight of third test: 40 Maximum on third test: 150 Score on third test: 101

OpenStudy (anonymous):

instead of Weight of first test: 30 Maximum on first test: 100 Score on first test: 93 Weight of second test: 30 Maximum on second test: 100 Score on second test: 87 Weight of third test: 40 Maximum on third test: 150 Score on third test: 101

OpenStudy (ajprincess):

After each cin statement which enables u to input test score insert cout<<endl;. hope this works:)

OpenStudy (ajprincess):

cout << "Weight of first test:"; cin >> weight1; cout << "Maximum on first test:"; cin >> test1; cout << "score on first test:"; cin >> score1; cout<<endl; cout << "Weight of second test:"; cin >> weight2; cout << "Maximum on second test:"; cout >> test2; cout << "Score on first test:"; cin >> score2; cout<<endl;

OpenStudy (anonymous):

let m see if that works

OpenStudy (ajprincess):

hmm k:)

OpenStudy (anonymous):

IT WORKED OMG .. sweeet

OpenStudy (anonymous):

not i can apply that to my outher project im working on too and it will be complete yay

OpenStudy (anonymous):

now*

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!