expected unqualified-id before int - c++

I got this error "expected unqualified-id before int" in c++ when I was trying to compile it.
void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
{
int age = startingAge;
int lastAge = startingAge + numOfYears;
double cash = yearlyAmount;
cout << "Age | Yearly Plan" << endl;
cout << "----+----------------" << endl;
while (age <= lastAge)
{
cout.width(3);
cout << age << " | ";
cout.width(15);
cout.precision(2);
cout.setf(ios::fixed);
cout << cash << endl;
if (age != lastAge)
cash = cash + cash*interestRate / 100.0;
age++;
}
system("pause");
}
I tried to find what went wrong but couldn't.

Hint:
void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
// --------------------------------------------------^

void yearlyWithdrawal(int startingAge, int numOfYears), int yearlyAmount, double interestRate)
The ) in the middle of this line could be an obvious pointer to a problem before 'an int'.

Related

Getting a -nan(ind) output when trying to find averages within an array (c++)

I am trying to get the averages of a set of numbers in an array and I am getting -nan(ind) as my output. I am unsure of what is causing this issue. Here is the code that I have written so far in C++:
#include "pch.h"
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
void input_from_file(ifstream & inFile, char * item, char * name, double & price, double & cost, double & material_cost);
double array_price[50], array_total_cost[50];
double price, base_cost, material_cost;
int cnt = 0, i;
double calAverage(double arr[], int s);
char item[2]{ "" };
char name[21];
double total_cost = base_cost + material_cost;
double profit = price - total_cost;
void File_Input(ifstream & Main_File)
{
do {
string File_Name;
cout << "Please enter the file name including extension: ";
cin >> File_Name;
Main_File.open(File_Name);
} while (!Main_File);
}
void File_Read(ifstream & The_File)
{
cout << setw(29) << left << "Name" << right << setw(10) << "Price" << setw(10) << "Cost" << setw(10) << "Profit" << "\n" << endl;
string Typed_File;
int increment = { 0 };
while (!The_File.eof())
{
input_from_file(The_File, item, name, price, base_cost, material_cost);
total_cost = base_cost + total_cost;
profit = price - total_cost;
array_total_cost[increment] = total_cost;
array_price[increment] = price;
increment++;
cout << setw(29) << left << name << right << setw(10) << price << setw(10) << total_cost << setw(10) << profit << endl;
};
cout << "\n\nThe average price is " << calAverage(array_price, cnt);
cout << "\nThe average cost is " << calAverage(array_total_cost, cnt) << " \n";
}
void input_from_file(ifstream & inFile, char * item, char * name, double & price, double & base_cost, double & material_cost)
{
inFile >> item;
inFile >> name;
inFile >> price;
inFile >> base_cost;
inFile >> material_cost;
array_price[cnt] = price;
array_total_cost[cnt] = base_cost + material_cost;
}
double calAverage(double arr[], int s)
{
int i;
double sum = 0;
for (i = 0; i < s; i++)
{
sum += arr[i];
}
return (sum/(double)(s));
}
int main()
{
ifstream The_File;
File_Input(The_File);
File_Read(The_File);
}
Here is the file that I am trying to read from:
food2.txt
D WhiteWine 3.5 0.75 0.0
F Courgetts 751.88 125.31 75.19
F BroccoliAuRoquefort 860.63 227.81 111.38
D RedWine 357.88 76.69 0.0
F CoqAuVin 774.38 129.06 77.44
F GratinDePates 886.13 234.56 114.68
F GnocchiAuxLegumes 368.38 78.94 55.23
F Raviole 796.88 132.81 79.69
F PatesFraichesAuNoix 911.63 241.31 117.98
D Milk 378.88 81.19 0.0
F RizAuCumin 819.38 136.56 81.94
F GratinDePolenta 937.13 248.06 121.28
D Coffee 389.38 83.44 0.0
F RisottoAuxAsperges 841.88 140.31 84.19
F GateauDePommes 962.63 254.81 124.58
D Tea 3.00 .69 0.0
F SoupeD'Epeautre 864.38 144.06 86.44
F Tartiflette 988.13 261.56 127.88
D WaterWithGas 4.38 5.23 0.0
F Aligot 886.88 147.81 88.69
F abcdefghijklmnopqrst 999.99 268.31 131.18
Here is the full output that I am getting:
output
Any help is appreciated. Thank you
Make sure you add cnt ++; to your while loop. Also try to stay away from global variables if possible. And as previously stated, here is a reason why eof is bad in a while loop
Not incrementing cnt leaves it at zero. This leads to calculating 0.0 / 0 which is NaN.

In C++ for the use of arrays within functions, where data is entered into arrays from a .txt file using ifstream

First time posting here. The question asks to use functions to calculate and out put into a table a payroll with gross, netpay and the like as well as output a condition into a text file. However my issue is with the functions refusing to loop when I use arrays.
#include <iostream>
#include <fstream>//File stream
#include <string> //For use with string variables
#include <iomanip>//For use with formatting
double hoursworked[6],hourlyrate[6];
int i;
using namespace std;
double gross_fun(double hourlyrate[], double hoursworked[],int &numofelements)
{
double overtime[6];
double gross[6];
for(i=0; i<=5; i++){
if (hoursworked[i] > 40){
overtime[i] = 1.5*hourlyrate[i] * (hoursworked[i]-40); //Overtime is 1.5 times hourly rate
gross[i]=overtime[i]+(40*hourlyrate[i]);
}
else
gross[i]= hourlyrate[i] * hoursworked[i];
return gross[i];
}
}
double taxes_fun(double gross[], int &numofelements)
{
double taxes;
for(i=0; i<=5; i++){
taxes = .1 * gross[i];
return taxes;
}
}
double SS_fun( double gross[], int &numofelements)
{
double social;
for(i=0; i<=5; i++){
social = .05 * gross[i];
return social;
}
}
double netpay_fun(double gross[], double tax[], double social[], int &numofelements)
{
double netpay;
for(i=0; i<=5; i++){
netpay= gross[i] - (tax[i] + social[i]); //Resultant net pay given when taxes and security are subtracted
return netpay;
}
}
double taxes(double tax[], int &numofelements);
double social_security (double social[], int &numofelements);
double netpay_fun (double netpay[], int &numofelements);
double gross_fun(double hourlyrate[], double hoursworked[], int &numofelements);
int main ()
{
ifstream inFile; //To read .txt file
inFile.open ("input.txt");
if (inFile.fail()){
cerr << "Error Opening File" << endl;
exit(1);
}
int EmpNum[6];//Employee Number
int i = 0; //Counter
double gross[6],taxes[6],socia[6],netpay[6],moneytopay[6];
double overtime[6],hoursworked[6],hourlyrate[6],social[6],totalnetpay = 0.0f;
char paytype[6];
string firstname[6],lastname[6];
cout << setprecision(2) << fixed; //Set double values to two decimal places
(inFile>>EmpNum[i]>>firstname[i]>>lastname[i]>>hoursworked[i]>>hourlyrate[i]>>paytype[i]){
i++;
}
for(i=0;i<=5;i++){
gross[i]=gross_fun(hourlyrate, hoursworked, i);
taxes[i] = taxes_fun(gross, i);
social[i] = SS_fun (gross, i);
netpay[i] = netpay_fun (gross, taxes, social, i);
totalnetpay=totalnetpay+netpay[i];
}
}
cout << setw(6) << "EmpNo"<< setw(13) << "First Name"<< setw(13) << "Last Name"<< setw(8) << "Gross";
cout << setw(8) << "Tax"<< setw(8) << "SS"<< setw(10) << "Net Pay"<< setw(9) << " Payment Type";
for(i=0;i<6;i++){
cout << setw(5) <<EmpNum[i]<< setw(11) <<firstname[i]<<setw(14) <<lastname[i]<< setw(11) << gross[i]<< setw(8) << taxes[i];
cout << setw(9) << social[i]<< setw(8) << netpay[i]<< setw(7) << paytype[i]<< endl;
}
cout<<"\nSum of netpay: "<<totalnetpay;
return 0;
}
The reason is simple, you have put you return statement inside your for loop. Just move it out.
double gross_fun(double hourlyrate[], double hoursworked[],int &numofelements) //Function to determine gross salary
{
double overtime[6];
double gross[6];
double total = 0.0;
for(i=0; i<=5; i++){
if (hoursworked[i] > 40){ //Calculating gross salary if hours worked greater than 40
overtime[i] = 1.5*hourlyrate[i] * (hoursworked[i]-40); //Overtime is 1.5 times hourly rate
gross[i]=overtime[i]+(40*hourlyrate[i]);
}
else
gross[i]= hourlyrate[i] * hoursworked[i]; //Calculating gross salary if no overtime is done
// remove here
}
return // something
}
You have done the same thing inside all your functions. If you want to return an array, i suggest you pass it in the parameters and return void. or return an array.

My code is returning two really weird errors

My code isn't working. I don't know why. The errors I am getting don't make sense.
17 18 C:\Users\the beast\Desktop\Case study phase 3.0.6.cpp [Error] a function-definition is not allowed here before '{' token
I dont even know why it throwing this error.
77 1 C:\Users\the beast\Desktop\Case study phase 3.0.6.cpp [Error] expected '}' at end of input
^ all brackets are present checked no idea why it is throwing this error
#include<iostream>
#include<fstream>
#include<string>
#include<cstdlib>
using namespace std;
//loading libraries
float const taxnet = .9;
float const taxwh = .1;
float employeenumber;
float payrate=0;
float gross=0;
float net=0;
float manhours=0;
float overtime=0;
float taxes=0;
char usercontrols;
void data_loop(char usercontrols);
void writeWorkerInfo(ofstream &stream, float employeenumber, float manhours, float payrate, float gross, float taxes, float net);
void payrollcalc(float employeenumber, float manhours, float payrate, float gross, float taxes, float net);
void data_entry(float employeenumber, float manhours, float payrate);
void data_recall(float employeenumber);
void data_error_check(char usercontrols);
int main(){
// varibles
cout << "Hit 1 to enter new data; hit 2 load a file; hit escpae to exit." << endl;
cin >> usercontrols;
while (usercontrols != 27){
data_error_check(usercontrols);
}
return 0;
}
void data_error_check(char usercontrols){
cin >> usercontrols;
if(usercontrols == 49 || 50){
data_loop(usercontrols);
}
else if (usercontrols != 49 ||50){
cout << "Wrong button hit enter to return to main menu" << end;
cin >> usercontols;
if(usercontrols == 13){
main();
}
}
}
void data_loop(char usercontrols){
cin >> usercontrols;
if (usercontrols == 49){
data_entry();
}
else(usercontrols == 50){
data_recall();
}
}
void writeWorkerInfo(ofstream &stream, float employeenumber, float manhours, float payrate, float gross, float taxes, float net){
stream << " Your ID is " << employeenumber << endl;
stream << " # of hours worked " << manhours << endl;
stream << " Your Hourly rate is " << payrate << endl;
stream << " Your Gross pay is " << gross << endl;
stream << " Your tax rate is " << taxwh << endl;
stream << " Amount of taxes " << taxes << endl;
stream << " Your net pay is " << net << endl;
data_loop();
}
void payrollcalc(float employeenumber, float manhours, float payrate, float gross, float taxes, float net){
if (manhours > 40) {
overtime = manhours - 40;
gross = ((manhours - overtime) * payrate) + ((payrate * 1.5)* overtime);
//overtime claculation
}
else {
gross = manhours * payrate;
//no overtime calculation
}
taxes = gross * taxwh;
net = gross * taxnet;
//writeWorkerInfo(float employeenumber,float manhours,float payrate,float gross,float taxwh,float taxes,float net);
std::string empnum = std::to_string(employeenumber);
ofstream payroll;
payroll.open(empnum + ".txt");
writeWorkerInfo(float employeenumber,float manhours,float payrate,float gross,float taxes,float net);
payroll.close();
}
void data_entry(float employeenumber,float manhours,float payrate){
cout << "Enter Employee ID:";
cin >> employeenumber;
cout << "Enter Number of Hours Worked:";
cin >> manhours;
cout << "Enter Pay rate:";
cin >> payrate;
payrollcalc();
}
void data_recall(float employeenumber){
cout << "Enter employee number";
cin >> employeenumber;
///reading in data
std::string empnum = std::to_string(employeenumber);
ofstream payroll;
payroll.open(empnum + ".txt");
payroll.close();
data_loop();
}
Just get the functions definitions out of the main block code and call them inside main
These points should explain why it's not working:
The function main() needs to return a type.
You are defining all your functions inside main(), place them above main or below with function prototypes.
You are using variables inside functions that aren't declared yet.
Funtions are made so that it can be used in defferent place of the program, making it inside the main scope makes less sense!
Moreover we can't define funtion inside another function, we can just call it from nother fuction that comes after its declaration!
2ndly your main says nothing about returning.
ReturnType FunctionName (dataType args, ...){ FuntionBody}
Refer to the above syntax of a funtion declaration.
A function must always provide its return type as prefix or void if it dont return anything!
Note: In some compiler void main() works just fine, but some compiler says main should return something. So as a standard method you must define main as int not void to safegaurd urself.

C++ Beginner Logic Error - Returning 0

I don't understand why my code is not calculating the birthrate and the deathrate. I keep on getting 0 for both. I included the static_cast<double> to ensure this wouldn't happen. Any feedback / help?
#include <iostream>
#include <string>
using namespace std;
double calculateBirthRate();
double calculateDeathRate();
class PopInfo
{
private:
string cityName;
long totalCityPopulation;
int numberOfBirths;
int numberOfDeaths;
double birthrate;
double deathrate;
int bir;
int dea;
long citpop;
public:
PopInfo()
{
cityName = "";
totalCityPopulation = numberOfBirths = numberOfDeaths = 0;
}
long getPopulation()
{
return totalCityPopulation;
}
int getBirths()
{
return birthrate;
}
int getDeaths()
{
return deathrate;
}
string getCity()
{
return cityName;
}
void setCityName(string nameOfCity)
{
cityName = nameOfCity;
}
void setTotalCityPopulation(long populationOfCity)
{
totalCityPopulation = populationOfCity;
}
void setNumberOfBirths(int birthNumbers)
{
numberOfBirths = birthNumbers;
}
void setNumberOfDeaths(int deathNumbers)
{
numberOfDeaths = deathNumbers;
}
void calculateBirthRate(PopInfo);
void calculateDeathRate(PopInfo);
};
int main()
{
PopInfo newCity;
string cit;
long citpop;
int bir;
int dea;
cout << "What is the city name?: " << endl;
cin >> cit;
cout << "What is the total city population?: " << endl;
cin >> citpop;
while (citpop < 1)
{
cout << "Please enter a valid total city population: " << endl;
cin >> citpop;
}
cout << "What are the number of births?: " << endl;
cin >> bir;
while (bir < 0)
{
cout << "Please enter a valid number of births: " << endl;
cin >> bir;
}
cout << "What are the number of deaths?: " << endl;
cin >> dea;
while (dea < 0)
{
cout << "Please enter a vaild number of deaths: " << endl;
cin >> dea;
}
newCity.setCityName(cit);
newCity.setTotalCityPopulation(citpop);
newCity.setNumberOfBirths(bir);
newCity.setNumberOfDeaths(dea);
cout << endl;
cout << "The city name is " << newCity.getCity() << endl;
cout << "The total city population is " << newCity.getPopulation() << endl;
cout << "The birth rate is " << newCity.getBirths() << endl;
cout << "The death rate is " << newCity.getDeaths() << endl;
return 0;
}
void PopInfo::calculateBirthRate(PopInfo newCity)
{
double birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
}
void PopInfo::calculateDeathRate(PopInfo newCity)
{
double deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
}
You accidentally made birthrate and deathrate as local variables. Remove the leading keyword double, to make it:
void PopInfo::calculateBirthRate(PopInfo newCity)
{
birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
}
void PopInfo::calculateDeathRate(PopInfo newCity)
{
deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
}
Even so, it's kind of strange that you're passing newCity by value – did you mean to store the rates back in the same object, as in:
void PopInfo::calculateBirthRate(PopInfo& newCity)
{
newCity.birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
}
void PopInfo::calculateDeathRate(PopInfo& newCity)
{
newCity.deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
}
or did you mean to operate on the object in-place, as in:
void PopInfo::calculateBirthRate()
{
birthrate = static_cast<double>(bir) / citpop;
}
void PopInfo::calculateDeathRate()
{
deathrate = static_cast<double>(dea) / citpop;
}
I don't think you ever call the functions that calculate birth rate and death rate! That is on top of the issues already identified, but I'm pretty sure it matters... Put a cout debug statement in there and see if I'm right...
Another problem: since "rate" is a number between zero and 1, and your function getBirths returns an int, you are going to run into a rounding problem...
Also not sure you ever set dea and bir in the context of the class (you declare them at the main level). So many places where you are inviting problems...
The easiest solution would be to rewrite these two functions:
double getBirths()
{
return (double)numberOfBirths/citypop;
}
double getDeaths()
{
return (double)numberOfDeaths/citypop;
}
But read your code, and ask yourself what the scope of your variables is, where they are set (and if you ever set them...), where they are used, where you perform type conversions.... You can learn a lot from that.
EDIT
I couldn't help myself, and decided to copy your program and debug it. After a few simplifications in the structure I came up with the following (note I moved the two functions calculateBirthRate and calculateDeathRate inside the class definition for consistency; and I used the "internally known" variables totalCityPopulation etc, rather than some of the "alternative" ones you were using... it was getting very confusing. Finally, as I mentioned in the original answer - I made sure the birth and death rates were actually calculated. I have marked changed lines with //*** :
#include <iostream>
#include <string>
using namespace std;
double calculateBirthRate();
double calculateDeathRate();
class PopInfo
{
private:
string cityName;
long totalCityPopulation;
int numberOfBirths;
int numberOfDeaths;
double birthrate;
double deathrate;
int bir;
int dea;
long citpop;
public:
PopInfo()
{
cityName = "";
totalCityPopulation = numberOfBirths = numberOfDeaths = 0;
}
long getPopulation()
{
return totalCityPopulation;
}
double getBirths() //*** was int
{
return birthrate;
}
double getDeaths() //*** was int
{
return deathrate;
}
string getCity()
{
return cityName;
}
void setCityName(string nameOfCity)
{
cityName = nameOfCity;
}
void setTotalCityPopulation(long populationOfCity)
{
totalCityPopulation = populationOfCity;
}
void setNumberOfBirths(int birthNumbers)
{
numberOfBirths = birthNumbers;
}
void setNumberOfDeaths(int deathNumbers)
{
numberOfDeaths = deathNumbers;
}
//*** this function moved into the class definition
void calculateBirthRate()
{
birthrate = (double)numberOfBirths/totalCityPopulation; //*** using different variables
}
//*** this function moved into the class definition
void calculateDeathRate()
{
deathrate = (double)numberOfDeaths / totalCityPopulation; //*** using different variables
}
};
int main()
{
PopInfo newCity;
string cit;
long citpop;
int bir;
int dea;
cout << "What is the city name?: " << endl;
cin >> cit;
cout << "What is the total city population?: " << endl;
cin >> citpop;
while (citpop < 1)
{
cout << "Please enter a valid total city population: " << endl;
cin >> citpop;
}
cout << "What are the number of births?: " << endl;
cin >> bir;
while (bir < 0)
{
cout << "Please enter a valid number of births: " << endl;
cin >> bir;
}
cout << "What are the number of deaths?: " << endl;
cin >> dea;
while (dea < 0)
{
cout << "Please enter a vaild number of deaths: " << endl;
cin >> dea;
}
newCity.setCityName(cit);
newCity.setTotalCityPopulation(citpop);
newCity.setNumberOfBirths(bir);
newCity.setNumberOfDeaths(dea);
newCity.calculateBirthRate(); //*** added, or it's never calculated
newCity.calculateDeathRate(); //*** added, or it's never calculated
cout << endl;
cout << "The city name is " << newCity.getCity() << endl;
cout << "The total city population is " << newCity.getPopulation() << endl;
cout << "The birth rate is " << newCity.getBirths() << endl;
cout << "The death rate is " << newCity.getDeaths() << endl;
return 0;
}
When I run this code, I get the following:
What is the city name?:
Amsterdam
What is the total city population?:
1234567
What are the number of births?:
12345
What are the number of deaths?:
54321
The city name is Amsterdam
The total city population is 1234567
The birth rate is 0.00999946
The death rate is 0.044
The diff between your code and mine is:
33c33
< double getBirths()
---
> int getBirths()
38c38
< double getDeaths()
---
> int getDeaths()
68,71c68,69
< void calculateBirthRate()
< {
< birthrate = (double)numberOfBirths/totalCityPopulation;
< }
---
> void calculateBirthRate(PopInfo);
> void calculateDeathRate(PopInfo);
73,76d70
< void calculateDeathRate()
< {
< deathrate = (double)numberOfDeaths / totalCityPopulation;
< }
117,118d110
< newCity.calculateBirthRate();
< newCity.calculateDeathRate();
129a122,125
> void PopInfo::calculateBirthRate(PopInfo newCity)
> {
> double birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
> }
130a127,130
> void PopInfo::calculateDeathRate(PopInfo newCity)
> {
> double deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
> }
double birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
...
double deathrate = static_cast<double>(newCity.dea) / newCity.citpop;
Here you are driving two new variable names birthrate and death rate. You're not writing the values two the class data members. Writing the type before the names overwrites it. To change, simply remove it.
birthrate = static_cast<double>(newCity.bir) / newCity.citpop;
...
deathrate = static_cast<double>(newCity.dea) / newCity.citpop;

ERROR "cannot convert 'float' to 'float...'..."

There are probably other little formatting errors in here that I'll need to fix, etc. but what I need help with is what to do with the following:
Lab8pt1.cpp: In function 'float Salary(float, float)':
Lab8pt1.cpp:48: error: assignment of function 'float Salary(float, float)'
Lab8pt1.cpp:48: error: cannot convert 'float' to 'float ()(float, float)' in assignment
Lab8pt1.cpp:50: error: assignment of function 'float Salary(float, float)'
Lab8pt1.cpp:50: error: cannot convert 'double' to 'float ()(float, float)' in assignment
Lab8pt1.cpp:51: error: cannot convert 'float (*)(float, float)' to 'float' in return
I know it's referring to my Salary function, but I'm not sure what the issue with my float is. This is just supposed to be a simple Lab Assignment that teaches us how to use functions (we only have to write the code for the functions, the rest was given to us).
Help, please! Thanks in advance!
#include <iostream>
#include <iomanip>
#include <string>
using namespace std ;
void Header(void) ;
float Salary(float Hours, float Pay_Rate);
void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name);
void Read(float &hour, float &Pay_R,string &name) ;
bool Verify(float Hours, float Pay_Rate);
int main ( void )
{
float Pay_Rate, Hours, Sal, Tax;
const float Tax_Rate= (float)0.09 ;
string name;
Header();
for(int i = 0 ; i < 3 ; i++){
Read(Hours,Pay_Rate,name);
Sal = Salary(Hours,Pay_Rate);
Print_it(Hours,Pay_Rate,Sal, Tax_Rate,name);
}
cout<<"\n\n\n**********\t End of report \t*****\n\n\n\n";
return 0 ;
}
void Header( void )
{
string name;
cout << "Welcome, " << name << ", to the Salary Calculator: a program that will calculate your salary.";
return;
}
float Salary(float Hours, float Pay_Rate)
{
if( Hours <= 40 )
Salary = Hours * Pay_Rate;
else if( Hours > 40)
Salary = Hours * (Pay_Rate * 1.5);
return(Salary);
}
void Print_it(float Hours,float Pay_Rate,float Sal, float Tax_Rate, string Name)
{
cout << fixed << setprecision(2);
cout << "Name: " << left << setw(15) << Name << endl;
cout << "Hours worked: " << left << setw(15) << Hours << endl;
cout << "Pay rate: " << left << setw(15) << Pay_Rate << endl;
cout << "Tax rate: " << left << setw(15) << Tax_Rate << endl;
cout << "Salary: " << left << setw(15) << Sal << endl;
return;
}
void Read(float &hour, float &Pay_R,string &name)
{
cout << "Please enter your name: ";
getline(cin, name);
cout << "Please enter number of hours worked: ";
cin >> hour;
cout << "Please enter your pay rate: ";
cin >> Pay_R;
return;
}
bool Verify(float Hours, float Pay_Rate)
{
if( Hours < 0 || Hours > 60 || Pay_Rate < 0 || Pay_Rate > 500)
return false;
else
return true;
}
Salary = Hours * Pay_Rate;
Salary is the function name. You can not assign a float value to it. You need to declare a float variable and return that variable.
float sal;
sal = Hours * Pay_Rate;
return sal;
In fact you don't need this variable. You can directly return within the if-else block.
if( Hours <= 40 )
return Hours * Pay_Rate;
Note that method and variable names should start with a lowercase letter, class name should start with uppercase. This is widely used convention.
its the function you are trying to return.
float Salary(float Hours, float Pay_Rate)
{
if( Hours <= 40 )
Salary = Hours * Pay_Rate;
else if( Hours > 40)
Salary = Hours * (Pay_Rate * 1.5);
return(Salary);
}
there is no variable salary defined in this function
Corrected code is:
float Salary(float Hours, float Pay_Rate)
{
float salary;
if( Hours <= 40 )
salary = Hours * Pay_Rate;
else if( Hours > 40)
salary = Hours * (Pay_Rate * 1.5);
return(salary);
}