Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 21994

Is it possible to add two float inside the for loop?

$
0
0

I'm creating a simple grade calculator with C++, I'm just new in C++, and I am practicing it, but I am having a problem with my method or with my code, hope you'll help me out with this one. I don't have an idea if it is possible to add up the user input (using float numbers) inside the for loop method and print it out. Thank you and happy new year!

#include <iostream>
#include <iomanip>

using namespace std;

int main() {
    float sum = 0.00, avg, grades [10], i;

    cout << "\n Enter your grades on each subject\n";
    cout << "-----------------------------------------------";
    cout << "\n Chemistry for Engineers Laboratory: ";
    cin >> grades [0];
    cout << "\n Chemistry for Engineers: ";
    cin >> grades [1];
    cout << "\n Computer Aided Drafting: ";
    cin >> grades [2];
    cout << "\n Calculus";
    cin >> grades [3];
    cout << "\n Kontekstwalisadong Komunikasyon sa Filipino at sa Iba't-ibang Larangan: ";
    cin >> grades [4];
    cout << "\n Science Technology and Society: ";
    cin >> grades [5];
    cout << "\n Mathematics in the Modern World: ";
    cin >> grades [6];
    cout << "\n Movemement Enhancement (Physical Education): ";
    cin >> grades [7];
    cout << "\n Readings in Philippine History: ";
    cin >> grades [8];
    cout << "\n Undertanding the Self: ";
    cin >> grades [9];

    for ( i = 0; i < 10; i++) {
        printf ("%.1f + %.1f\n", sum , avg, sum+avg);
    }
    cout << "----------------------------------------";
    cout << "Total Grade: "<< sum;
    avg = sum / 10;
    cout << "\n GWA: "<< avg;
    cout << "\n Rating: ";

    if ( avg > 1.00) {
        cout << "Excellent";
    } else if ( avg > 3.00 && avg <= 2.00) {
        cout << "Passed";
    } else if ( avg > 4.00 && avg <= 3.00) {
        cout << "Conditional Passing";
    } else {
        cout << "Failed";
    }
    return 0;
}

Viewing all articles
Browse latest Browse all 21994

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>