Q:

Rewrite your grading program to use the conditional operator (§ 4.7, p. 151) in place of the if–else statement

0

Rewrite your grading program to use the conditional operator (§ 4.7, p. 151) in place of the if–else statement.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

#include <vector>
#include <string>
#include <iostream>

int main() {
  const std::vector<std::string> scores = { "F", "D", "C", "B", "A", "A++"};
  std::string lettergrade;
  int grade;
  std::cin >> grade;
  lettergrade = grade < 60 ? scores[0] : scores[(grade - 50) / 10];
  std::cout << lettergrade << std::endl;

  return 0;
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now