1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
// How do I return true into the other functionside, and how can I call
// functions within functions.
// These are the instructions that I'm working with:
// Write a function classify() which will receive three parameters
// (at this point, they must be valid values).
// This function will call the two functions described below, as follows.
// Using the function ratesonescore(), classify() will rate each of the
// three scores, one at a time.
// There will be three calls to this function, one for each score.
// Then classify() will use the function findtotalscore() to find the total
// of the three scores.
// Then classify() will use the function ratethegroup() to rate the three
// scores and the total together. Finally, classify() will return
// to the main program.
// 3. Write a function rateonescore() which will receive one parameter
// representing a valid SAT score. The function will determine which
// of the following three categories the score is in: less than 500,
// 500 or above, or 800 (perfect score). Note this function gets one parameter.
// The function will print a message indicating which of these
// three categories occurred.
#include <iostream>
// "...Write a function classify() which will receive three parameters..."
// --> classify(int one, int two, int three)
// "...classify() will return to the main program..."
void classify(int one, int two, int three);
// "...will use the function ratethegroup() to rate the three
// scores and the total together..."
void ratethegroup(int one, int two, int three, int total);
// "...Write a function rateonescore() which will receive one parameter
// representing a valid SAT score..."
void rateonescore(int satvalue);
// "...will use the function findtotalscore() to find the total
// of the three scores..."
int findtotalscore(int one, int two, int three);
bool isitavalidgroup(int group[]);
int main()
{
int sat_scores[3] {};
for(int i{0}; i<3; i++) {
std::cout << "Please, insert a SAT score in the range 200-800: ";
std::cin >> sat_scores[i];
}
if(isitavalidgroup(sat_scores)) {
classify(sat_scores[0], sat_scores[1], sat_scores[2]);
} else {
std::cout << "Sorry, not a valid group...";
}
return 0;
}
bool isitavalidgroup(int group[])
{
for(int i{0}; i<3; i++) {
if(group[i]<200 || 800<group[i] || group[i]%10) {
return false;
}
}
return true;
}
void classify(int one, int two, int three)
{
// "...Using the function ratesonescore(), classify() will rate each of the
// three scores, one at a time..."
std::cout << "The first score belongs to the category ";
rateonescore(one);
std::cout << "The second score belongs to the category ";
rateonescore(two);
std::cout << "The third score belongs to the category ";
rateonescore(three);
int total = findtotalscore(one, two, three);
// Sorry, can't help from this point on
ratethegroup(one, two, three, total);
}
// "...The function will determine which of the following three categories
// the score is in: less than 500, 500 or above, or 800 (perfect score)...
// The function will print a message indicating which of these
// three categories occurred..."
void rateonescore(int satvalue)
{
if(satvalue < 500) {
std::cout << "less than five hundreds - not so good.\n";
} else if (satvalue >= 500 && satvalue < 800) {
std::cout << "more than four hundreds ninety-nine - good.\n";
} else if (satvalue == 800) {
std::cout << "eight hundreds - perfect match!\n";
}
}
int findtotalscore(int one, int two, int three)
{
return one + two + three;
}
// "...will use the function ratethegroup() to rate the three
// scores and the total together..."
void ratethegroup(int one, int two, int three, int total)
{
// Can't understand what the requirement asks to do!
}
| |