samedi 17 septembre 2016

C++ homework average score calculator

I'm in a class of C++ and I am kind of a novice in all in it. the thing is I have this homework (I can see that is simple) but I don't know how to star nor to end with it. Could you help me solve it?

Instructions:

1) The program aims to calculate the average among given three scores. The procedure is as follows. a. Write C++ statement that include the header file iostream. b. Write a C++ statement that allows you to use cout, and endl without the prefix std::. c. Write C++ statement that declare the following int variables: score1, score2, and score3 d. Write C++ statement that declare the float-point variable average e. Write C++ statements that get user inputs for score1, score2, and score3 f. Write a C++ statement that stores the average of score1, score2, and score3, into average. g. Write C++ statement that output the value of score1, score2, score3, and the average with 2 precision digits. h. Compile and run your program.

Snippet:

/*

Problem statement: 1) The program aims to calculate the average among given three scores. The procedure is as follows.

a. Write C++ statement that include the header file iostream. b. Write a C++ statement that allows you to use cout, and endl without the prefix std::. c. Write C++ statement that declare the following int variables: score1, score2, and score3 d. Write C++ statement that declare the float-point variable average e. Write C++ statements that get user inputs for score1, score2, and score3 f. Write a C++ statement that stores the average of score1, score2, and score3, into average. g. Write C++ statement that output the value of score1, score2, score3, and the average with 2 precision digits. h. Compile and run your program.

2) Read the attached program skeleton, where some statements are missing. Please fill in the missing statements to make the skeleton complete. Note: Please insert the statements just after the comment lines, where starts with "// TODO". Please do not delete those comment lines */

#include <iostream>
#include <iomanip>

using namespace std;
int main(){

    // TODO declare and initialize three integer variables, score1, score2, and score3.

    float average = 0;

    cout << "Please type three scores: ";
    // TODO wait user to type three scores and store them to integer variables, score1, score2, and score3.

    // TODO calculate the average score and assign the float-point result to the float-point variable average

    // TODO set the display control for float-point value so that all the float-point values will hold two precision digits

    cout << "The average of three scores (" << score1 << ", " << score2 << ", and " << score3 << ") is " << average << "." << endl;

    cin.ignore(1124, '\n');
    cin.get();
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire