Start learning free

LESSON 170 OF 409 · PROJECTS: EVERYDAY PROGRAMS

Report Card V2 - Weighted Score in C++

Practice

Combine variables and arithmetic to compute a student's weighted final score.

Weights: Homework 20%, Midterm 30%, Final 50%. Each weighted part is rounded down to a whole number before the parts are added.

You start with:

int homework = 90;
int midterm = 82;
int finalExam = 88;

Build:

Score: 86

Rules:

  • Compute score = homework * 20 / 100 + midterm * 30 / 100 + finalExam * 50 / 100.
  • Each part is rounded down because int divided by int drops the remainder (the third variable is named finalExam).
  • For the starting data: 18 + 24 + 44 = 86.
  • Print "Score: " followed by the score, for example cout << "Score: " << score << endl;

The third variable is named finalExam. int / int truncates, so each weight already rounds down.

int homework = 90;
int midterm = 82;
int finalExam = 88;

int score = homework * 20 / 100 + midterm * 30 / 100 + finalExam * 50 / 100;
cout << "Score: " << score << endl;

STEP 1 OF 2
    Ctrl + Enter to check

    Report Card V2 in C++

    Keep going with C++About 340 step-by-step lessons, from your first line of code to coding interviews. Free to start.
    Start learning free