#include #include #include float all = 0; void calculateCharges(float cus[]); in
ID: 3685772 • Letter: #
Question
#include
#include
#include float all = 0;
void calculateCharges(float cus[]);
int main(){ float cus[3];
printf ("Please input the first customer's hours ");
scanf("%f", &cus[0]);
printf("Please input the second customer's hours ");
scanf("%f", &cus[1]);
printf("Please input the third customer's hours ");
scanf("%f", &cus[2]);
printf("%s%10s%10s ", "Car", "Hours", "Charge");
//calculateCharges(cus[0]);
//calculateCharges(cus[1]);
calculateCharges(cus);
printf("%s%10.1f%10.1f ", "TOTAL", cus[0] + cus[1] + cus[2], all); return 0; }
void calculateCharges(float cus[])
{ float result=0.0;
static int car=1;
for(int x=0;x<3;x++)
{ if (cus[x] <= 3)
{ result = 2; }
else if (cus[x] > 3&&cus[x]<24)
{ result = 2 + 0.5 * ceil(cus[x]-3); }
else if (cus[x] >= 24){ result = 10; }
printf("%-d%10.1f%10.1f ", car, cus[x], result);
car++; all += result; } }
Convert this to c++
Explanation / Answer
#include <iostream>
#include<math.h>
#include<iomanip>
using namespace std;
float all=0;
void calculateCharges(float cus[]);
int main()
{
float cus[3];
cout<<"Please input the first customer's hours ";
cin>>cus[0];
cout<<"Please input the second customer's hours ";
cin>>cus[1];
cout<<"Please input the third customer's hours ";
cin>>cus[2];
cout<<"Car "<<"Hours "<<"Change ";
calculateCharges(cus);
cout<< "Total "<<setprecision(1)<<cus[0]+cus[1]+cus[2]<<" "<<setprecision(1)<<all<<endl;
//printf("%s%10.1f%10.1f ", "TOTAL", cus[0] + cus[1] + cus[2], all);
return 0;
}
void calculateCharges(float cus[])
{
float result=0.0;
static int car=1;
for(int x=0;x<3;x++)
{
if (cus[x] <= 3)
{
result = 2;
}
else if (cus[x] > 3&&cus[x]<24)
{
result = 2 + 0.5 * ceil(cus[x]-3);
}
else if (cus[x] >= 24)
{
result = 10;
}
cout<<car<<" "<<setprecision(1)<<cus[x]<<" "<<setprecision(1)<<result<<endl;
//printf("%-d%10.1f%10.1f ", car, cus[x], result);
car++; all += result;
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.