You are here:

C++/functions

Advertisement


Question
Why isn't this compiling? I want user to input time entered and left parking lot and it computes charges.
Textpad program
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;

void getData(int& hours, char type)
double calculateFee(int hours, char type);
void printTime(double fee);
char AMPM;

int main()
{
int hours;
double fee;
char type;

getData(hours,type);
fee=calculateFee(int hours, type);
printTime(fee);
  return 0;
}

void getData(int& hours, char type);
{int enterHr, enterMin;
  cout<<"Enter vehicle type: "<<endl;
cin>>type;
cout<<"Time Entered Hrs:Minutes: "<<endl;

cin>>enterHr;
cin.ignore(1);
cin>>enterMin;
cin>>enterAMPM;
cout<<"Time Left Hrs:Minutes: "<<endl;
cin>>exitHr;
cin>>ignore(1);
cin>>exitMin;
cin>>exit AMPM;
if (enterMin>0)
hours=1;
if (hours=PM)
hours=24-hours+10;
hours=12%hours;
}

double calculateFee( int hours, char type)
{
if(type==c)
  {
     if (hours<=2)
     hours = 0;
     else if (hours<=5)
      hours= hours+ (hours*.50);
     else
  hours=hours+( hours*.25);
}

  cout<<"You owe $ "<<fee<<endl;
  if(type==t)
{
     if (hours<=1)

     hours= 0;

     else if (hours>=3)

     hours= hours+(hours*1.0)

     else if (hours>=15)

     hours=hours+(hours*.75);
}
}
void printTime(double fee)

{if (type==s)
{
cout<<"Charges = $0"<<endl;
else
cout<<"Charges:  "<<fee<<endl;
}
}
Error E2141 A:\parking meter\parkingmeter.cpp 8: Declaration syntax error
Error E2268 A:\parking meter\parkingmeter.cpp 19: Call to undefined function 'calculateFee' in function main()
Error E2188 A:\parking meter\parkingmeter.cpp 19: Expression syntax in function main()
Error E2040 A:\parking meter\parkingmeter.cpp 25: Declaration terminated incorrectly

Answer
there are many errors. For instance:
1. you have to put a ';' at the end of getData() prototype
2. you have not closed the main function while opene the declaration of other functions.
3. instead of ';' you have to use '{' in declaration of calculateFee() and getData()

Your code needs major modification.

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Sam

Expertise

You may ask me about simple to complicated C/C++ programming methods/style and most like questions about network programming in C++.

Experience

I'm a professional programer in C++ and network/internet programming.

©2016 About.com. All rights reserved.