Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Here is my code, we are trying to create a program to calculate gpa. How do I ge

ID: 670062 • Letter: H

Question

Here is my code, we are trying to create a program to calculate gpa. How do I get it to where the classes with grade of W or I are not calculated in the GPA? I have also had a few other issues. 1) When I type a class (for example programming foundations 1 causes the program to not work) if I type it as programmingfoundations1 with no spaces it works just fine? 2) How can I get spaces inbetween prompts for class 1 and class 2 so that it is easier to read and not clumped together?

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

int main()
{
int i=0;
float totalScore=0;
float nclasses, score, coursescore, coursehours;
   string classname;
   string coursenumber;
   float gpa, totalhours;
char grade,coursegrade;

cout << "Enter the total number of classes you want to calculate: ";
cin >> nclasses;

   cout << "Please enter the proper information when prompted. Enter course grades as (A, B, C, D, F, W, I): " << endl;
  
   for(i = 0; i < nclasses; i++){

cout << "Enter name class " << i+1 << " :";
cin >> classname;

cout << "Enter your course number: ";
cin >> coursenumber;

       cout << "Enter your course grade: ";
       cin >> coursegrade;

       cout << "Enter course credit hours: ";
       cin >> coursehours;

       grade = coursegrade;

if(grade == 'A') score = 4;
else if(grade == 'B') score = 3;
else if(grade == 'C') score = 2;
else if(grade == 'D') score = 1;
else if(grade == 'F') score = 0;
       else if(grade == 'W'); //not used in calculation
else if(grade == 'I'); //not used in calculation
       else{
           cout << "This class will not be used in GPA calculation.";
       }   

coursescore = score * coursehours;
totalScore += coursescore;
       totalhours += coursehours;
}
gpa = (float)totalScore / totalhours;
cout << "Your GPA is: " << gpa << endl;

return 0;
}

Explanation / Answer

#include<iostream>

#include<string>

using namespace std;

int main()

{

int i=0;

float totalScore=0;

float nclasses, score, coursescore, coursehours;

string classname;

string coursenumber;

float gpa, totalhours;

char grade,coursegrade;

cout << "Enter the total number of classes you want to calculate: ";

cin >> nclasses;

cout << "Please enter the proper information when prompted. Enter course grades as (A, B, C, D, F, W, I): " << endl;

  

for(i = 0; i < nclasses; i++){

cout << " Enter name class " << i+1 << " :";

cin >> classname;

cout << "Enter your course number: ";

cin >> coursenumber;

cout << "Enter your course grade: ";

cin >> coursegrade;

cout << "Enter course credit hours: ";

cin >> coursehours;

grade = coursegrade;

if(grade == 'A') score = 4;

else if(grade == 'B') score = 3;

else if(grade == 'C') score = 2;

else if(grade == 'D') score = 1;

else if(grade == 'F') score = 0;

else if(grade == 'W'); //not used in calculation

else if(grade == 'I'); //not used in calculation

else{

cout << "This class will not be used in GPA calculation.";

}

coursescore = score * coursehours;

totalScore += coursescore;

totalhours += coursehours;

  

}

gpa = (float)totalScore / totalhours;

cout << "Your GPA is: " << gpa << endl;

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote