I need help with a code for averaging grades it works on a online compiler but it doesn't work on visual studio 2019

Recommended Answers

All 4 Replies

#include <iostream>
using namespace std;

int main()

    float firstgrade, secondgrade, thirdgrade, fourthgrade;

    cout << "Enter your grades: ">> intl; 
    cin >> firstgrade >> secondgrade >> thirdgrade >> fourthgrade;

    // Determining letter grades
    const int
        A = 90,
        B = 80,
        C = 70,
        D = 60;

    float average=0.0;
    average = (float)(firstgrade + secondgrade + thirdgrade
        + fourthgrade) / 4;
    cout << "The average of their grades is: " << average;

    //What is your letter grade?
    if (average >= 90)

        cout << "Your average is an A. \n";

    else if (average >= 80)

        cout << "Your average is a B. \n";

    else if (average >= 70)

        cout << "Your average is a C. \n";

    else if (average >= 60)

        cout << "Your average is a D. \n";

    else if (average >= 0)

        cout << "Your average is an F. \n";

    else

        cout << "Invalid test score.\n";

    return 0;

It may be too late for you to fix your post. That first line in such a big font states include but what?

Also take time to share what's not working and the error messages since many may not load up your project to see what is amiss. Besdes the first few lines look off to me.

The include had # as the first char so it was interpreted as heading, thus the big font. I fixed it and now you can see the target as <iostream>.

commented: Much better looking. Thank you. +0

Now that your code display is fixed can you answer more questions?

  1. Where are your brackets? { and }
  2. Line 8 looks odd. Read http://www.cplusplus.com/doc/tutorial/basic_io/ to see how to use cout.

There's more but as presented this won't work in any C++ compiler I know of.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.