Question

The following is solved using C++ in Vocareum: In this problem, you will be prompting a...

The following is solved using C++ in Vocareum:

In this problem, you will be prompting a student for grades and credits for courses taken. From that, you will calculate a GPA.

This site: http://www.back2college.com/gpa.htm shows you how to calculate a GPA.

Keep prompting the student if they want to add more courses.

IMPORTANT NOTES!


  • The course name is prompted for, but nothing is done with it.
  • We are just using the grades A, B, C, D, and F so you won't have to do so much typing!
  • You will need to use the "set precision" command as shown in the book. Set it to "fixed" and "2".
  • You will need to use the "cin.ignore()" function as discussed earlier in the course.

The output should be:

Enter a course name: CMPSC 101

Enter number of credits: 3

Enter your grade (A, B, C, D, F): A

Continue ('Yes' or 'No')? Yes

Enter a course name: BIO 100

Enter number of credits: 3

Enter your grade (A, B, C, D, F): B

Continue ('Yes' or 'No')? Yes

Enter a course name: ACCT 50

Enter number of credits: 1

Enter your grade (A, B, C, D, F): D

Continue ('Yes' or 'No')? No

Total grade points: 22

Total credits attempted: 7

My following code is as follows:

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(){
string course, grade;
string answer = "Yes";
int gpa;
int point = 0;
int credits = 0;
int tgpoint = 0;
int gpoint = 0;
int tcredits = 0;
float tgpa = 0.0;
  
while(answer == "Yes"){
cout << "Enter a course name: ";
getline (cin, course);
cout << course << endl;
  
cout << "Enter number of credits: ";
cin >> credits;
cout << credits << endl;
  
cout << "Enter your grade (A, B, C, D, F): ";
cin >> grade;
cout << grade << endl;
  
  
if(grade == "A"){
point = 4;
}
if(grade == "B"){
point = 3;
}
if(grade == "C"){
point = 2;
}
if(grade == "D"){
point = 1;
}
if(grade == "F"){
point = 0;
}
  
cout << "Continue ('Yes' or 'No')? ";
cin >> answer;
cout << answer << endl;
cin.ignore (-1);
}
  
cout << "Total grade points: ";
cout << tgpoint << endl;
  
cout << "Total credits attempted: ";
cout << tcredits << endl;
  
cout << "Your GPA is: ";
cout << fixed;
cout << setprecision(2) << tgpa << endl;
  
return 0;
}

The output only reaches the fourth line. Along with the error, it reads as follows:

==================== YOUR OUTPUT =====================                                                                                                                         

0001: Enter~a~course~name:~CMPSC~101                                                                                                                                           

0002: Enter~number~of~credits:~3                                                                                                                                               

0003: Enter~your~grade~(A,~B,~C,~D,~F):~A                                                                                                                                      

0004: Continue~('Yes'~or~'No')?~Yes                                                                                                                                            

0005: Enter~a~course~name:                                                                                                                                                     

                                                                                                                                                                               

                                                                                                                                                                               

=================== MISMATCH FOUND ON LINE 0005: ===================                                                                                                           

ACTUAL  : Enter~a~course~name:                                                                                                                                                 

EXPECTED: Enter~a~course~name:~BIO~100                                                                                                                                         

======================================================     

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Thanks for the question.
Here is the completed code for this problem. Comments are included so that you understand whats going on. Let me know if you have any doubts or if you need anything to change.
Thank You !!
========================================================================================

#include <iostream>
#include <iomanip>
#include <string>

using namespace std;

int main(){
string course, grade;
string answer = "Yes";
int gpa;
int point = 0;
int credits = 0;
int tgpoint = 0;
int gpoint = 0;
int tcredits = 0;

while(answer=="Yes" || answer=="yes"){
cout << "Enter a course name: ";
getline (cin, course);

  
cout << "Enter number of credits: ";
cin >> credits;

tcredits+=credits;
  
cout << "Enter your grade (A, B, C, D, F): ";
cin >> grade;

  
if(grade == "A"){
point = 4;
}
if(grade == "B"){
point = 3;
}
if(grade == "C"){
point = 2;
}
if(grade == "D"){
point = 1;
}
if(grade == "F"){
point = 0;
}
tgpoint+=point*credits;

  
cout << "Continue ('Yes' or 'No')? ";
cin >> answer;
cin.ignore(256,'\n');
}
  
cout << "Total grade points: ";
cout << tgpoint << endl;
  
cout << "Total credits attempted: ";
cout << tcredits << endl;
  
cout << "Your GPA is: ";
cout << fixed;
cout << setprecision(2) << static_cast<double>(tgpoint)/tcredits << endl;
  
return 0;
}

============================================================================================

Add a comment
Know the answer?
Add Answer to:
The following is solved using C++ in Vocareum: In this problem, you will be prompting a...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This is for a C++ program: I'm almost done with this program, I just need to...

    This is for a C++ program: I'm almost done with this program, I just need to implement a bool function that will ask the user if they want to repeat the read_course function. I can't seem to get it right, the instructions suggest a do.. while loop in the main function. here is my code #include <iostream> #include <cstring> #include <cctype> using namespace std; const int SIZE = 100; void read_name(char first[], char last[]); void read_course(int & crn, char des[],...

  • #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int...

    #include <iostream> #include <conio.h> #include<limits> using namespace std; int main(){ char oparand, ch = 'Y'; int num1, num2, result; while(ch == 'Y'){ cout << "Enter first number: "; cin >> num1; while(1){//for handling invalid inputs if(cin.fail()){ cin.clear();//reseting the buffer cin.ignore(numeric_limits<streamsize>::max(),'\n');//empty the buffer cout<<"You have entered wrong input"<<endl; cout << "Enter first number: "; cin >> num1; } if(!cin.fail()) break; } cout << "Enter second number: "; cin >> num2; while(1){ if(cin.fail()){ cin.clear(); cin.ignore(numeric_limits<streamsize>::max(),'\n'); cout<<"You have entered wrong input"<<endl; cout <<...

  • c++ programming : everything is done, except when you enter ("a" ) in "F" option ,...

    c++ programming : everything is done, except when you enter ("a" ) in "F" option , it does not work. here is the program. #include <iostream> #include <string> #include <bits/stdc++.h> #include <iomanip> #include <fstream> using namespace std; #define MAX 1000 class Inventory { private: long itemId; string itemName; int numberOfItems; double buyingPrice; double sellingPrice; double storageFees; public: void setItemId(long id) { itemId = id; } long getItemId() { return itemId; } void setItemName(string name) { itemName = name; } string...

  • I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7:...

    I need help with this code. I'm using C++ and Myprogramming lab to execute it. 11.7: Customer Accounts Write a program that uses a structure to store the following data about a customer account:      Customer name      Customer address      City      State      ZIP code      Telephone      Account balance      Date of last payment The program should use an array of at least 20 structures. It should let the user enter data into the array, change the contents of any element, and display all the...

  • C++ language I need to update this code with the following: ask the user for how...

    C++ language I need to update this code with the following: ask the user for how many structures they would like. Once you get the number, allocate an array of pointers. Once they have been created, proceed to loop through and get the data as usual, and display it back to the screen. struct record {    int age;    string name; }; int check(record r[], int n, string nm) {    for (int i = 0; i < n;...

  • Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score...

    Modify Assignment #18 so it drops each student’s lowest score when determining the students’ test score average and Letter grade. No scores less than 0 or greater than 100 should be accepted #include<iostream> #include<string> using namespace std; int main() { double average[5]; string name[5]; char grade[5]; for(int i=0; i<=5; i++) { cout<<"Enter student name: "; cin.ignore(); getline(cin,name[i]); int sum=0; for(int j=0; j<5; j++) { int grades; cout<<"Enter Grades:"<<j+1<<" : "; cin>>grades; sum+=grades; } average[i]=(float)sum/5; if(average[i]>=90 && average[i]<=100) grade[i]='A'; else if(average[i]>=80...

  • Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string...

    Convert to use functions where possible #include<iostream> #include<string> using namespace std; int main() {    string first, last, job;    double hours, wages, net, gross, tax, taxrate = .40;    double oPay, oHours;    int deductions;    // input section    cout << "Enter First Name: ";    cin >> first;    cout << "Enter Last Name: ";    cin >> last;    cin.ignore();    cout << "Enter Job Title: ";    getline(cin, job);    cout << "Enter Hours Worked:...

  • Need help with a C++ program. I have been getting the error "this function or variable...

    Need help with a C++ program. I have been getting the error "this function or variable may be unsafe" as well as one that says I must "return a value" any help we be greatly appreciated. I have been working on this project for about 2 hours. #include <iostream> #include <string> using namespace std; int average(int a[]) {    // average function , declaring variable    int i;    char str[40];    float avg = 0;    // iterating in...

  • Consider the following statements: struct nameType { string first; string last; }; struct courseType { string...

    Consider the following statements: struct nameType { string first; string last; }; struct courseType { string name; int callNum; int credits; char grade; }; struct studentType { nameType name; double gpa; courseType course; }; studentType student; studentType classList[100]; courseType course; nameType name; Mark the following statements as valid or invalid. If a statement is invalid, explain why. student.course.callNum = "CSC230"; cin >> student.name; classList[0] = name; classList[1].gpa = 3.45; name = classList[15].name; student.name = name; cout << classList[10] << endl;...

  • The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried t...

    The following C++ code include 3 files: Patient.h, Patient.cpp and Main.cpp. The program basically creates and stores patient records. The original code has everything in a single .cpp file. I tried to divide the code in 3 parts (Patient.h, Patient.cpp and Main.cpp), but it is giving me errors. Patient.h #ifndef PATIENT_H #define PATIENT_H #include <string> #include "Patient.cpp" using namespace std; class Patient{ private : string firstname; string lastname; string location; static int cnt; int id; public : Patient(string, string, string);...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT