Question

The program runs but the math is not correct ( output for amount ) #include <iostream>...

The program runs but the math is not correct ( output for amount )

#include <iostream>

using namespace std;
int main()
{

int hoursParked;
double total;
double Car = 2.50 ;
double Truck = 5.50;
double Bus = 19.00;
double rateC = 1.50;
double rateT = 3.75;
double rateB = 6.75;
char type;


cout << "Please Enter number of hours parked and the type of car (Type: (C)ar or (T)ruck or (B)us): " << endl;
cin >> type >> hoursParked;


switch (type)
{
case 'C':
case 'c':
{
if (hoursParked <= 2.00)
total = 2 * 1.25;
else
total = (( hoursParked - 2.00 )* rateC)+ Car ;
}
case 'T':
case 't':
{
if (hoursParked <= 2.00)
total = Truck;
else
total = ((hoursParked - 2.00) * rateT) + Truck;
break;
}
case 'B':
case 'b':
{
  
if (hoursParked <= 2.00)
total = Bus;
else
total = ((hoursParked - 2.00)*rateB) + Bus;
break;
}
}
cout << "Vehicle type: ";
if(type == 'C')
cout << "Car" << endl;
else if(type == 'T')
cout << "Truck" << endl;
else
cout << "Bus" << endl;
cout << "Time:" << hoursParked << endl;
cout << "Amount Due:$" << total <<endl;

return 0;
}

Homework Answers

Answer #1

I made slight changes to your program so that it will perform accurately. You have not given any input conditions, so that I have taken like parking charges are made minimum for 2 hours. The program had compiled and running accordingly

#include <iostream>
using namespace std;
int main()
{
int hoursParked;
double total;
double Car = 2.50 ;
double Truck = 5.50;
double Bus = 19.00;
double rateC = 1.50;
double rateT = 3.75;
double rateB = 6.75;
char type;

cout << "Please Enter number of hours parked and the type of car (Type: (C)ar or (T)ruck or (B)us): " << endl;
cin >> type >> hoursParked;

switch (type)
{
case 'C':
case 'c':
{
if (hoursParked <= 2.00){
total = 2 * 1.25;
}
else{
total = (( hoursParked - 2.00 )* rateC)+ Car ;
}
cout << "Vehicle type: " << "Car"<<endl << "Time:" << hoursParked <<endl <<"Parking Charges $"<<total<<endl;
break;
}
case 'T':
case 't':
{
if (hoursParked <= 2.00)
total = Truck;
else
total = ((hoursParked - 2.00) * rateT) + Truck;

cout << "Vehicle type: " << "Truck "<<endl << "Time:" << hoursParked <<endl <<"Parking Charges $"<<total<<endl;
break;
}
case 'B':
case 'b':
{
if (hoursParked <= 2.00)
total = Bus;
else
total = ((hoursParked - 2.00)*rateB) + Bus;
cout << "Vehicle type: " << "Bus "<<endl << "Time:" << hoursParked <<endl <<"Parking Charges $"<<total<<endl;
break;
}
}
return 0;
}

Output:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath>...
Please write variables and program plan (pseudocode) of the C++ programming below: #include <iostream> #include <cmath> using namespace std; void divisors(int num); int main () {    char repeat;    int num;       while (repeat !='n')    {        cout << "Enter a number: ";        cin >> num;        divisors(num);        cout << "Continue? (y or n): ";        cin >> repeat;    }    return 0; } void divisors(int num) {   ...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std;...
Rewrite the following program using switch statements. //Set 7.1 #include <iostream> #include <iomanip> using namespace std; int main() {        int x;        cout << "Selection option " << endl;        cin >> x;        if (x == 1)               cout << "You select option 1" << endl;        else if (x >= 2 || x <= 4)               cout << "You select options 2 or 3 or 4" << endl;               else if (x == 10)               cout << "You select option 10" << endl;               else...
//Calculate the even parity for letters, (A, Z, D, a). #include <iostream> #include <bitset> using namespace...
//Calculate the even parity for letters, (A, Z, D, a). #include <iostream> #include <bitset> using namespace std; int main() { char c; int bitCounts, pBit;; while (cin>>c){ //ctrl-Z to stop bitset<8> bs(c); cout<<bs<<endl; bitCounts = bs.count(); pBit = bitCounts % 2? 1: 0; cout<<"Even Parity bit: "<<pBit<<endl; } }
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in...
C++ #include<iostream> #include<string> #include<fstream> #include<cstdlib> using namespace std; const int ROWS = 8; //for rows in airplane const int COLS = 4; void menu(); //displays options void displaySeats(char[][COLS]); void reserveSeat(char [ROWS][COLS]); int main() { int number=0; //holder variable char seatChar[ROWS][COLS]; for (int i = 0; i < ROWS; i++) { for (int j = 0; j < COLS; j++) { seatChar[i][j] = '-'; } } int choice; //input from menu bool repeat = true; //needed for switch loop while (repeat...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include...
Please write variables and program plan (pseudocode) of the C++ programming code below: #include <iostream> #include <cmath> using namespace std; int getWeight(); float deliveryCharge(int weight); void displayCharge(int weight); int main () {    displayCharge(getWeight());    return 0; }   int getWeight() {    int weight;    cout << "Enter package weight (oz): ";    cin >> weight;    return weight; } float deliveryCharge(int weight) {    if (weight > 16)    {        return (((weight - 16) / 4) *...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double...
Need someone to fix my code: #include<iostream> using namespace std; struct student { double firstQuizz; double secondQuizz; double midTerm; double finalTerm; string name; }; int main() { int n; cout<<"enter the number of students"<<endl; cin>>n; struct student students[n]; int i; struct student istudent; for(i=0;i<n;i++) {    cout<<"Student name?"; cin >> istudent.name; cout<<"enter marks in first quizz , second quizz , mid term , final term of student "<<i+1<<endl; cin>>students[i].firstQuizz>>students[i].secondQuizz>>students[i].midTerm>>students[i].finalTerm; } for(i=0;i<n;i++) { double marks=0; double score=students[i].firstQuizz+students[i].secondQuizz+students[i].midTerm+students[i].finalTerm; marks=(students[i].firstQuizz*0.25)+(students[i].secondQuizz*0.25)+(students[i].midTerm*0.25)+(students[i].finalTerm*0.50); double totalArrgegateMarks =...
Write a program that reads a string and outputs the number of lowercase vowels in the...
Write a program that reads a string and outputs the number of lowercase vowels in the string. Your program must contain a function with a parameter of a char variable that returns an int. The function will return a 1 if the char being passed in is a lowercase vowel, and a 0 for any other character. The output for your main program should be: There are XXXX lowercase vowels in string yyyyyyyyyyyyyyyyyyyyyy Where XXXX is the count of lowercase...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void...
in C++ Need a heap-sort function #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Your code here ----------------- } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc...
Quick sort func in C++ #include <iostream> #include <stdlib.h> #include <string> using namespace std; void MyFunc ( int *array ) { // Code here } int main(int argc,char **argv) { int *Sequence; int arraySize; // Get the size of the sequence cin >> arraySize; // Allocate enough memory to store "arraySize" integers Sequence = new int[arraySize];    // Read in the sequence for ( int i=0; i<arraySize; i++ ) cin >> Sequence[i]; // Run your algorithms to manipulate the elements...
This code it's not working, fix it for me please #include <iostream> using namespace std; class...
This code it's not working, fix it for me please #include <iostream> using namespace std; class People {    string name;    double height; public:    void setName(string name)    {        this->name = name;    }    void setHeight(double height)    {        this->height = height;    }    double getHeight() {        return height;    }    string getName()    {        return name;    } }; int main() {    const int size...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT