I have been working on this code for awhile. Each time I fix an issue more appear. Can anyone help me figure out what I am doing wrong?
My output is to reflect:
How many exercises to input? 3
Score received for exercise 1: 10
Total points possible for exercise 1: 10
Score received for exercise 2: 7
Total points possible for exercise 2: 12
Score received for exercise 3: 5
Total points possible for exercise 3: 8
Your total is 22 out of 30, or 73.33%
1 #include<iostream>
2 using namespace std;
3
4 int main()
5 {
6
7 int totalPoints = 0, totalScore = 0, numOfExercise = 0, score = 0, points = 0;
8 double percent = 0;
9
10 cout<<"How many exercises to input?";
11 cin>>numOfExercises;
12 int numOfExercises;
13
14 cout<<"Score received for exercise 1:";
15 cin>>score;
16 cout<<"Total points possible for exercise 1:";
17 cin>>points;
18
19 cout<<"Score received for exercise 2:";
20 cin>>score;
21 cout<<"Total points possible for exercise 2:";
22 cin>>points;
23
24 cout<<"Score received for exercise 3:";
25 cin>>score;
26 cout<<"Total points possible for exercise 3:";
27 cin>>points;
28
29 cout.setf(ios: :fixed);
30 cout.setf(ios: :showpoint);
31 cout.precision(2);
32
33 totalScore+=score;
34 totalPoints+=points;
35 percent = totalScore/totalPoints*100.0;
36
37 cout<<"Your total amount of points is "<< totalScore << " out of " << totalPoints << " , or " <<percent<< " % "<<endl;
38 return 0;
39 }
There's an inconsistency in the spelling of a variable - numOfExercise or numOfExercises
If you want to keep a running total of score and points, the code needs to update the value of totalScore and totalPoints after the values for each exercise are read in, not just once at the end. score and points get overwritten by the values in the next exercise read in.
Have you covered for loops yet? This would be a good case to use a for loop.
We did some for and if statements but when I asked my professor if this program needs a loop he said it is not necessary. I will put the totalScore+=score and totalPoints+=points after each exercise.
Seriously, how do you expect us to help you when you don't show us the current state of your code, or tell us what the "issues" are? What on earth do you think we can do?
Sorry, I attempted to re-post the error messages but the the application I was using to practice my code with before writing it would not show me the error messages anymore. I am not trying to make anyone upset and don't want to get yelled at on here. I am just trying to understand c++ and reach out for help
#include <iostream>
#include <iomanip> //for setprecision()
usingnamespace std;
int main()
{
cout << endl << endl; //Create two spaces at the beginning so that things look clean
cout << " *** CALCULATE YOUR TOTAL SCORE ***" << endl << endl;
//Variable decleration
int totalPoints = 0, totalScore = 0, numOfExercise = 0, score1 = 0, score2 = 0, score3 = 0, points1 = 0, points2 = 0, points3 = 0;
//Take values of exercises and scores
cout << " How many exercises to input? ";
cin >> numOfExercise;
cout << endl; //in C++ cout<<endl; is preffered to \n to create a line as cout<<endl; clears the buffer while \n doesn't!
cout << " Scores received for exercise 1: ";
cin >> score1;
cout << " Total points possible for exercise 1: ";
cin >> points1;
cout << endl;
cout << " Scores received for exercise 2: ";
cin >> score2;
cout << " Total points possible for exercise 2: ";
cin >> points2;
cout << endl;
cout << " Scores received for exercise 3: ";
cin >> score3;
cout << " Total points possible for exercise 3: ";
cin >> points3;
//Do calculations
totalScore = score1 + score2 + score3;
totalPoints = points1 + points2 + points3;
//Calculate percent
cout << fixed << setprecision(2);
double percent = (double)totalScore / totalPoints * 100;
//Print results on screen
cout << endl;
cout << " Your total score is " << totalScore << " out of " << totalPoints << " or " << percent << "%" << endl << endl;
return 0;
}
*** CALCULATE YOUR TOTAL SCORE ***
How many exercises to input? 3
Scores received for exercise 1: 10
Total points possible for exercise 1: 10
Scores received for exercise 2: 7
Total points possible for exercise 2: 12
Scores received for exercise 3: 5
Total points possible for exercise 3: 8
Your total score is 22 out of 30 or 73.33%
Press any key to continue . . .
Remember to post specific questions! I am also a beginner and i understand how frustrating it can be to be stuck with an exercise. I used the simple arithmetic way. I understand seniors in the room would do this with few lines but that is what i got for now. Good luck pal!