Design and run a program that takes a numerical score and outputs a letter grade. Specific numerical scores and letter grades are listed below:

  90-100    =   Grade A
  80-89     =   Grade B
  70-79     =   Grade C
  60-69     =   Grade D
   0-59     =   Grade F

In this program, create two void functions titled getScore and printGrade with an int argument. The function getScore should have a Reference parameter and printGrade should have a Value parameter.

The function getScore will prompt the user for the numerical score, get the input from the user, and print the numerical score. The function printGrade will calculate the course grade and print the course grade. (Be careful and note that the assignment requires you to input the grade into getScore and not directly into the main function.)

Do not forget to put in the proper prompts and appropriate output messages. (Note: This program is a natural for use of the switch command, but if?else structures will also work.)

This is what I have so far

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int count;
int score;

int getScore();
void printGrade( int score );

int main()
{    
    for ( count = 1; count <= 10; count++ )
    {
         getScore();

         printGrade( int score );
    }

    system( "pause");

    return 0;
}

int getscore( int )
{
     cout << " Enter a number score ";
     cin >> score;
     cout << score;

     return score;
}

void printGrade( int score )
{
    if ( score >= 90 )
       cout << "A";
    else if ( score >= 80 )
       cout << "B";
    else if ( score >= 70 )
       cout << "C";
    else if ( score >= 60 )
       cout << "D";
    else 
       cout << "F";
}

I keep getting the error message Line 21 C:\Dev-Cpp\WA 2 part 2.cpp expected primary-expression before "int"

Can someone please tell me what that means or what I need to do to fix it and make this program work?

Welcome to DaniWeb!

First, please use code tags when you post code. It makes it much easier for us to read.

Second, PLEASE do not use global variables. The assignment even says that you should return the value by reference.

The actual error you are getting is because you have written

printGrade( int score );

instead of simply

printGrade( score );

Good luck,

Dave

Next time, please wrap your code around with the code tag. It would be easier to read.

#include <iostream>
using std::cout;
using std::cin;
using std::endl;

int count;
int score;

int getScore();                // function prototype
void printGrade( int score );  // function prototype

int main() {
  for ( count = 1; count <= 10; count++ ) {
    getScore();

    // you are not declaring function but calling it
    // so please do as daviddoria comment
    // printGrade( int score ); << original
    printGrade(score);  //  << changed to

  }

  system( "pause");  // not really a good idea to use this, use cin.get() better

  return 0;
}

// problem here as well, you declare it without 'int',
// but you declare definition with 'int' here.
// int getscore( int ) {  << original
int getscore() {  // << change to
  cout << " Enter a number score ";
  cin >> score;
  cout << score;

  return score;
}

void printGrade( int score ) {
  if ( score >= 90 )
    cout << "A";
  else if ( score >= 80 )
    cout << "B";
  else if ( score >= 70 )
    cout << "C";
  else if ( score >= 60 )
    cout << "D";
  else
    cout << "F";
}

Hope this help...

Thank you for the help and advice. I am unsure how to utilize cin.get(). I have used seen it used in code but not enough to understand its true function. I only use system pause so I can make sure that I am receiving the correct output. Otherwise the program runs and closes so fast that I cannot determine if what I was attempting to do was actually accomplished. As for the revised code, I am now receiving a linker error "undefined reference to getScore()" and ID returned one exit status. I am just gonna turn in what I have as is, but I would really appreciate further help with this problem. It is very frustrating having tried to rewrite this code so many times and not being able to figure out why it wont work.

can you post your current code that you have now?

the current code is what Taywin posted, granted i did put proper spacing in it for the parenthesis and such.

did you copy his code exactly? it seams to me like you might have getScore defined one way and declared another way.

yes, I did. Most of what was written there was what I had come up with all I did was make a few minor changes based on his suggestions.

Well can you post what you have now? What Taywin posted should compile so I would need to see your code to find out what is going on.

ok here it is

#include <iostream>

using std::cout;
using std::cin;
using std::endl;
   
int count;
int score;
   
int getScore();
void printGrade( int score );
  
int main() 
{
  for ( count = 1; count <= 10; count++ ) 
  {
      getScore();
  
      printGrade( score );
  
  }
  
  system( "pause" );
  
  return 0;
}
  
  
int getscore() 
{ 
  cout << " Enter a number score ";
  cin >> score;
  cout << score;
  
  return score;
}
  
void printGrade( int score ) 
{
  if ( score >= 90 )
       cout << "A";
  else if ( score >= 80 )
       cout << "B";
  else if ( score >= 70 )
       cout << "C";
  else if ( score >= 60 )
       cout << "D";
  else
      cout << "F";
}

look at line 10 and line 29. Notice anything different?

int getScore(); // line 10
int getscore()  // line 29
{
    //...

oh, wow I didnt even think about that, thank you so much

No problem. Glad to help.

My bad, didn't check the case of function declaration. :(

no worries, you were very helpful. sorry i didnt place the code in the code wrap at first. This was my first posting and i didnt realize that you could do that.

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.