So my lecturer gave me this assignment:
1. You are employed to develop a program for a car rental company, The program should
keep track of how much money you make per day from rental. Declare a Rental struct
that keeps track of how many cars are rented, the cost per rental, how much you earned
each day, and how many cars are left on the lot (given a total of 100 cars). Read in values
for how many cars are rented, and the cost pre rental. Pass the Rental struct to a function
called printmsg (Rental) that prints each of the values.
given:
money earned = cars rented * amount per rentalÍž
cars on lot = total cars - cars rentedÍž
I'm not sure how to pass the struct to the function correctly because the returning values are totally incorrect. Please if someone could assist me I would be grateful, just starting C++ for the first time.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
#include <iostream>
#include <math.h>
using namespace std;
struct Rental
{
float rented_cars;
float rental_cost;
float daily_earn;
float lot_cars;
int total_cars = 100;
};
int main ()
{
Rental A;
float printmsg(Rental A);
cout<<"Enter the number of cars rented"<<endl;
cin>>A.rented_cars;
cout<<"What is the cost per rental"<<endl;
cin>>A.rental_cost;
cout<<"The money earned each day is: "<<A.daily_earn<<endl;
cout<<"The number of cars left on the lot is: "<<A.lot_cars<<endl;
}
float printmsg(Rental B)
{
B.daily_earn = B.rented_cars*B.rental_cost;
B.lot_cars = B.total_cars-B.rented_cars;
return B.daily_earn;
}
|