I really need to practice on declarations in c++. I don't entirely get when it needs to be done and where...
But for the most part my code compiles except for line 125: "in function void getChoice(char) then the 4 character instances in my while loop all say "not declared in this scope"
At first I tried a reference variable named &letter in the function getChoice and that didn't work either. I need it to finish compiling to so I can debug it.
here is my code for my function. how do i get the compiler to accept it?
/* This program is for a hospital to show fees for an inpatient or outpatient.
*/
#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
void getChoice(char);
double totalCharges(double, double);
// Default RATE argument included. If rate changes update here.
double totalCharges(int, double, double, double RATE= 50.00);
int main()
{
char choice; // used for menu selection.
double medicationCost;
double servicesCost;
int daysStayed;
double total; // Calculated sum of all totals.
cout << "Which records would you like to look up. (I) for inpatient\n";
cout << "or (O) for outpatient.\n";
getChoice(choice); // Displays options and validates input.
// Format output
cout << fixed << showpoint << setprecision(2);
switch(choice)
{
//Inpatient choice
case 'i' :
case 'I' : cout << "How long in days did the patient stay at the hospital: ";
cin >> daysStayed;
// Validate input for daysStayed. Cannot be less than 0.
while (daysStayed < 0)
{
cout << "Please enter a number 0 or more: ";
cin >> daysStayed;
}
cout << "Enter the total cost of all medications: ";
cin >> medicationCost;
// Validate input for medicationCost. Cannot be less than 0
while (medicationCost < 0)
{
cout << "Please enter a number 0 or more: ";
cin >> medicationCost;
}
cout << "Enter the total cost of all hospital services: ";
cin >> servicesCost;
// Validate input for servicesCost. Cannot be less than 0
while (servicesCost < 0)
{
cout << "Please enter a number 0 or more: ";
cin >> servicesCost;
}
// Calculate the total charges
total = totalCharges(daysStayed, medicationCost, servicesCost);
// Display the total charges.
cout << "The total cost of this patient's hospital stay is $ "
<< total << ".\n";
break;
// Outpatient choice
case 'o' :
case 'O' : cout << "Enter the total cost of all medications: ";
cin >> medicationCost;
// Validate input for medicationCost. Cannot be less than 0
while (medicationCost < 0)
{
cout << "Please enter a number 0 or more: ";
cin >> medicationCost;
}
cout << "Enter the total cost of all hospital services: ";
cin >> servicesCost;
// Validate input for servicesCost. Cannot be less than 0
while (servicesCost < 0)
{
cout << "Please enter a number 0 or more: ";
cin >> servicesCost;
}
// Calculate the total charges
total = totalCharges(medicationCost,servicesCost);
// Display the total charges.
cout << "The total cost of this patient's hospital stay is $ "
<< total << ".\n";
break;
}
return 0;
}
//**********************************************************************
// Definition of function getChoice.
// function recieves user character input to select an option. Uses reference variable.
//**********************************************************************
void getChoice(char choice)
{
cout << "Enter choice I or O: " << endl;
cin >> choice;
// Validatation: Make sure choices I or O are used.
while(choice != O && choice != o && choice != I && choice != i)
{
cout << "Enter only O for outpatient records or I\n";
cout << "for inpatient records.\n";
cin >> choice;
}
}
//**********************************************************************
// Definition of function totalCharges. Called from inpatient selection.
// Function calculates the total charges and returns result for inpatients.
//**********************************************************************
double totalCharges(int daysStayed, double medicationCost, double servicesCost, double RATE)
{
// Calculate total charges.
return (daysStayed * RATE) + servicesCost + medicationCost;
}
//**********************************************************************
// Definition of function totalCharges. Called from outpatient selection.
// Function calculates the total charges and returns result for outpatients.
//**********************************************************************
double totalCharges(double medicationCost, double servicesCost)
{
// Calculate total charges.
return (medicationCost + servicesCost);
}
}
*edit included all source code.
This post has been edited by J-e-L-L-o: 20 March 2011 - 12:04 AM

New Topic/Question
Reply


MultiQuote



|