Quantcast
Channel: CodeGuru Forums - Visual C++ Programming
Viewing all articles
Browse latest Browse all 3027

C++ while statement and switch statment

$
0
0
I'm creating a program for my assignment and keep running into problems:
Assignment requirements:
Write a program that lets a User enter letter grades of A,B,C,D or F and counts the number of A's, B's, C's, D's and F's. The User should enter a grade of Z to end data entry. Hence, the screen should include something like:
: (a description of what the program will do)
:
Please enter a letter grade or Z to stop ==> B
Please enter a letter grade or Z to stop ==> C
Please enter a letter grade or Z to stop ==> C
Please enter a letter grade or Z to stop ==> E
Sorry, E is not a valid grade.
Please enter a letter grade or Z to stop ==> d
:
:
Please enter a letter grade or Z to stop ==> A
Please enter a letter grade or Z to stop ==> Z

There were 3 A's
There were 1 B's
There were 5 C's
There were 2 D's
There were 0 F's

Requirements:
Your program must use a switch statement.
Use a while() loop with SENTINEL value Z

This is my program so far also I keep getting error C2660: 'updateCounts' : function does not take 5 arguments:

// A program that lets a User enter letter grades and counts the number each grade.


#include <iostream> // provides cout, etc.
using namespace std;

void explain_prog_to_user();
// tells user what the program does

void decimal_format();
// formats decimals nicely in output stream os


void updateCounts (char grade, int& countA, int& countB, int& countC, int& countD, int &countF);


const char SENTINEL = 'Z';

int main()
{
char default=0;
char grade;
int numA=0, numB=0, numC=0, numD=0, numF=0; //accumulator variables needed to report at end

explain_prog_to_user(); // tell user what proegam does

decimal_format(); // decimals formatted nicely on screen

cout << "\n Please enter a letter grade or\n" << SENTINEL << "to stop\n";
cin >> grade;
grade=toupper(grade);

while(grade != SENTINEL)
{

if(grade== default)
cout << "Grade invalid. Please try again \n\n";
else
{
cout << "\nPlease enter your grade: ";
cin >> grade;



// update grade counts
updateCounts (numA, numB, numC, numD, numF);

}

// start to process next worker

cout << "\n Please enter a letter grade or\n" << SENTINEL << "to stop\n";
cin >> grade;
grade=toupper(grade);

}

// output final total grade counts

cout << " Totals: \n";
cout << "Number of A " << numA << endl;
cout << "Number of B " << numB << endl;
cout << "Number of C " << numC << endl;
cout << "Number of D: " << numD << endl;
cout << "Number of F: " << numF<< endl;


system("pause");
return 0;

}

void explain_prog_to_user()
{
cout << "\nThis program calculates the number of grades of A, B, C, D, and F \n\n";

}

void decimal_format()
{
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
}



void updateCounts (char grade, int& countA, int& countB, int& countC, int& countD, int& countF)
// Precondition: grade is entered by user
// Postcondition: the grade for the current user’s has been increased by 1.
{
switch (grade)
{
case 'A': countA++;
break;
case 'B': countB++;
break;
case 'C': countC++;
break;
case 'D': countD++;
break;
case 'F': countF++;
break;
default: break;
};
return;
}

Viewing all articles
Browse latest Browse all 3027

Latest Images

Trending Articles



Latest Images