|
Getinput error. Error 2660. 4244, and 2447
Hello,
I'm getting a compiler error 2660, 4244, 2447 with the getinput function in my program. I've made several attempts to correct the error, but i can't figure it out. Any suggestions?
Blackstone99
/*********************************************************************
Filename: studentrecord.cpp
Program Description:
* This program gets student information from previous and current quarters.It
* then calculates and displays the new cumulative GPA, current GPA,
* total credits, and student ID .
*********************************************************************/
#include <iostream.h> // cin, cout
#include <iomanip.h> // setprecision(), setiosflags()
void getInput(char [], int,int &, float &, int &,int &,float & );
void doCalculations(int &, float &, int &, float &, float &, int &, float &);
void displayOutput(char [], int, float, float);
float calculateGPA(int, int);
float calculateTotalGPA(float, int, float, int);
int calculatetotalcredits(int,int);
/*******************************************************************************
* Function: main()
* Description: Gets student information from the keyboard, performs calculations
* on it, then prints it to the screen.
* Inputs: Reads input from the keyboard.
* Outputs: Writes output to the screen.
* Preconditions: <None>
* Postconditions: Prints to the screen and takes input from the keyboard.
*******************************************************************************/
void main(void)
{
const int studentIDLength = 10; // Length of studentID[]
char studentID[studentIDLength]; // Student ID#
int previousCredits; // Number of credits previously
int previouscoursegrades; // Number of previous grade points
float currentGradePoints; // Number of honor points this quarter // completed
float previousGPA; // Previous GPA
int currentCredits; // Number of credits this quarter
int currentcourses; // Number of courses taken this quarter
float currentGPA; // GPA for this quarter
int totalCredits; // Total credit units
float totalGPA; // Overall GPA
//
// Get input from user.
//
getInput(studentID, studentIDLength, previousGPA,
previousCredits, currentcourses, previouscoursegrades);
//
// Perform calculations.
//
doCalculations(currentGPA, totalGPA, totalCredits);
//
// Output results.
//
displayOutput(studentID, currentGPA, totalGPA, totalCredits);
}
/*******************************************************************************
* Function: getInput()
* Description: Prompts for input and takes input for eight variables
* Inputs: All input is taken from the keyboard
* Outputs: All prompts are output to the screen
* Preconditions: studentID entered from keyboard must be no longer than
* studentIDLength - 1. studentName entered from keyboard must be
* no longer than studentNameLength - 1. Only integer
* numbers must be entered where integers are expected. Only
* floating point numbers must be entered where floating point
* numbers are expected.
* Postconditions: Output is displayed on screen. studentID{},
* currentGPA,totalCredits, totalGPA.
* variables are modified.
*******************************************************************************/
void getInput(/* Out */ char studentID[], // Student ID#
/* In */ int studentIDLength, // Length of studentID[]
/* Out */ int &previousCredits, // Number of credits previously
/* Out */ float &previousGPA, // Previous GPA
/* Out */ int &previouscoursegrades, // Number of previous honor points
/* Out */ int ¤tCredits, // Number of credits this quarter
/* Out */ int ¤tcourses, // Number of courses taken this quarter
/* Out */ float ¤tGradePoints); // Number of grade points
{
{
int previouscredits; // Number of credits from input
int previouscoursegrades; // Number of grade points from input
currentCredits = 0;
currentGradePoints = 0;
currentcourses= 0;
//
// Prompt for input and get input from keyboard.
//
cout << "Student ID#: ";
cin.getline(studentID, studentIDLength);
cout << "Previous GPA: ";
cin >> previousGPA;
cout << "Previous number of credits: ";
cin >> previousCredits;
cout << "Previous Grade Points: ";
cin >> previouscoursegrades;
cout << "Previous Grade Points: ";
cin >> currentCredits;
cout << "Number of couses taken: ";
cin >> currentcourses;
//
// Get credit unit values and grades from one line of input from keyboard.
//
cout << "Credit unit values and grades: ";
for(int i = 0; i < currentCourses; i++)
{
cin >> previouscredits;
cin >> previouscoursegrades;
currentCredits += previouscredits;
currentGradePoints += previouscoursegades* credits;
}
}
/*******************************************************************************
* Function: doCalculations()
* Description: Performs the calculations and returns the results through the
* parameters.
* Preconditions: <None>
* Postconditions: Changes currentGPA, totalCredits and totalGPA.
*******************************************************************************/
void doCalculations(
/* In */ int &previousCredits, // Number of credits
/* In */ float &previousGPA, // Previous GPA
/* In */ int ¤tCredits, // Current credits
/* In */ float ¤tGradePoints, // Number of grade
/* Out */ float ¤tGPA, // GPA for this quarter
/* Out */ int &totalCredits, // Total credit units
/* Out */ float &totalGPA, // Overall GPA
// quarter
{
currentGPA = calculateGPA(currentGradePoints, currentCredits);
totalCredits = calculatetotalcredits(previousCredits, currentCredits);
totalGPA = calculateTotalGPA(previousGPA, previousCredits, currentGradePoints,
totalCredits);
}
/*******************************************************************************
* Function: calculateGPA()
* Description: Given a the number of grade points and credits, this function
* calculates and returns the GPA.
* Preconditions: credits must not be zero.
* Postconditions: Returns the resulting GPA.
*******************************************************************************/
float calculateGPA(/* In */ float currentGradePoints, // Number of grade points
/* In */ int currentcredits) // Number of credits
{
float GPA; // Grade Point Average
GPA = currentGradePoints / currentcredits;
return GPA;
}
/*******************************************************************************
* Function: calculateTotalGPA()
* Description: Given the previous quarter's GPA, the previous quarter's
* credits, the current quarter's grade points and the total
* credits earned overall, this function calculates and returns
* the overall GPA.
* Preconditions: totalCredits must not be zero.
* Postconditions: Returns the resulting overall GPA.
*******************************************************************************/
float calculateTotalGPA(/* In */ float previousGPA, // Previous GPA
/* In */ int previousCredits, // Number of credits
// previously
// completed
/* In */ float currentGradePoints, // Number of grade
// points this
// quarter
/* In */ int totalCredits) // Total credits for all
// quarters
{
float totalGPA; // Overal GPA for all quarters
//
// Calculate overall GPA.
//
totalGPA = (previousGPA * previousCredits + currentGradePoints) / totalCredits;
return totalGPA;
}
/*******************************************************************************
* Function: displayOutput()
* Description: Prints the results of the calculations to the screen.
* Outputs: Prints all output to the screen.
* Preconditions: <None>
* Postconditions: Output is printed to the scree.
*******************************************************************************/
void displayOutput
(/* In */ char studentID[], // Student ID#
/* In */ int totalCredits, // Total credits completed
/* In */ float totalGPA, // Overall GPA
/* In */ float currentGPA, // GPA for this quarter
{
//
// Print results to screen.
//
cout << "Student ID#: " << studentID << endl;
cout << "Total number of credit units: " << totalCredits << endl;
cout << "Cumulative GPA: " << setprecision(2)
<< setiosflags(ios::fixed | ios::showpoint) << totalGPA << endl;
cout << "GPA for the current quarter: " << setprecision(2)
<< setiosflags(ios::fixed | ios::showpoint) << currentGPA << endl;
}
return 0;
Last edited by LuciWiz : 26-Mar-2006 at 09:17.
Reason: Please insert your C++ code between [c++] & [/c++] tags
|