Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

(Help please) Question on more than one functions

Status
Not open for further replies.

whatever1

Programmer
Nov 4, 2003
2
0
0
CA
I'm having some problems working a assignment I'm working on. It doesn't work! :( The program is suppose to output a letter grade given a student's test score. There is a main function and four functions for the four subtasks. Here the code. Thank you very much for your help! :)


#include <iostream>
#include <conio.h>

using namespace std;

void GetScore(double score);
//Purpose: This function asks the user to enter a score between 0 and 100
// inclusive. If the score is not between the two values then print
// an error message and ask for another score.
//
// Precondition:
// None
// Postcondition:
// The value of number has been set to an integer between 1 and 100 inclusive
//------------------------------------------------------------------------------

void DetermineGrade(double score, char grade);
//Purpose: This function determines the score and displays the grade for the
// value.
//
//Precondition:
// Grade is assigned.
//Postcondition:
// The score will determine and grade will be diplayed.
//------------------------------------------------------------------------------

void PrintGrade(double score, char grade);
//Purpose: This function prints the grade and score.
//
//Precondition:
//
//Postcondition:
//
//------------------------------------------------------------------------------

//void GetResponse(char response);
//Purpose: This function will ask whether they want to continue or not.
//
//Precondition:
//
//Postcondition:
//
//------------------------------------------------------------------------------

int main()
{
double score;
char grade;


GetScore( score);

cout << &quot;Please enter your score between 0 and 100 &quot;;
cin >> score;

getch();
return 0;
}

//------------------------------------------------------------------------------

void GetScore(double score)
{

cout << &quot;Please enter your score between 0 and 100 &quot;;
cin >> score;

while ((score < 0) || (score > 100))
{
cout << &quot;The score is: &quot; << score << &quot; is not between 1 and 100 inclusive.\n&quot;;
cout << &quot;Try again. Enter a score between 1 and 100: &quot;;
cin >> score;
}

}

void DetermineGrade(double score, char grade)
{

if (score >= 85)
grade = 'A';
else if (score >= 70)
grade = 'B';
else if (score >= 60)
grade = 'C';
else if (score >= 50)
grade = 'D';
else
grade = 'F';

}

void PrintGrade(double score, char grade)
{

cout << &quot;The score is: &quot; << score << endl;
cout << &quot;The grade is: &quot; << grade << endl;

}


 
Perhaps because you don't call DetermineGrade or PrintGrade anywhere?
 
void GetScore(double& score);
void DetermineGrade(double score, char& grade);

notice the &'s. You need to mark these parameters as references so the functions can change them and the values still exist after the functions have exited. Otherwise they're deleted.
 
whatever1, you should walk your code with debugger. After that, put it in the forum, if something is not clear.

Ion Filipski
1c.bmp

ICQ: 95034075
AIM: IonFilipski
filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top