Friday, June 1, 2018

Total Grade Using Your Own Inputs

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    vector <double> data;

    double input, input2;
    double total = 0, total2 = 0;

    cout << "\aEnter your score for each quiz, tests and/or homework (enter 0 to end): " << endl;

    do{
        cin >> input;
        data.push_back (input);

        total += input;

    } while (input != 0); // once input is 0, loop ends

    cout << "\aEnter max score for each quiz, tests and/or homework (enter 0 to end): " << endl;

    do{
        cin >> input2;
        data.push_back (input2);

        total2 += input2;

    } while (input2 != 0);

    data.pop_back();    // prevents counting 0, removes 1 array
                        // since both do loops uses data, the pop_back applies to both. If you want to use a different pop_back
                        // then you will need to change the variable, in this case: data

 //   int dataSize = int(data.size());
/* if and else to prevent dividing by 0 */
    if (total2 == 0)
        cout << "Undefined!" << endl;
    else
    cout << "Your grade is: " << (total/total2)*100 << "%" << endl;

}

No comments:

Post a Comment