So I'm trying to make this program loop that the initial total number of cars is 0, and the number of cars that will be left on the lot each day will be the total minus the rented cars. It should loop so that it continues to ask for rented cars and the rental cost, so after the first day the new total would be the lot cars, so it would continue each day until the number of cars left is obviously 0 or the number of cars asked for is more than the amount left, anyone can offer any help to tweak this code?
#include <iostream>
usingnamespace std;
struct Rental
{
float rented_cars;
float rental_cost;
float daily_earn;
int lot_cars;
int total_cars;
};
float printmsg(Rental R)
{
cout<<"The money earned each day = "<<R.daily_earn<<endl;
cout<<"The number of cars left on the lot = "<<R.lot_cars<<endl;
}
int main ()
{
Rental A;
cout<<"Enter the total number of cars"<<endl;
cin>>A.total_cars;
while(A.total_cars>0)
{
A.daily_earn = A.rented_cars*A.rental_cost;
A.lot_cars = A.total_cars-A.rented_cars;
A.lot_cars = A.total_cars;
cout<<"Enter the number of cars rented, then the cost per rental"<<endl;
cin>>A.rented_cars>>A.rental_cost;
printmsg(Rental (A));
}
}
That does not quite make sense. It could make sense if one daily action is buying new cars. I bet there is not.
The total number of cars is usually the sum of rented and "in lot" cars. (Handling demolished and stolen vehicles is extra.)
The basic transactions are renting and returning. When you rent a car out, the lot decreases by one, but the number of rented cars increases by one. Similarly, the return increases the lot and decreases the amount of rented.
Your business seems to rent cars for eternity and go bankrupt when all the cars are out, i.e. when you reach maximum revenue level (which would continue foreever).