Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can you please correct the mistake i want main to receive a value (total charge

ID: 3579046 • Letter: C

Question

can you please correct the mistake i want main to receive a value (total charge from the last function and print it?

#include

double total_charge(double hours, double charge);

void read(); i

nt main()

{

read( );

double calc = total_charge( ); \ trying to call the function and ask for receive the value

printf("Total charge is %lf", calc);

return 0;

}

void read()

{

double hours;

double charge;

printf(" hours worked: ");

scanf_s("%lf", &hours);

printf("charges of cleaning per hour: ");

scanf_s("%lf", &charge);

total_charge(hours, charge);

}

double total_charge(double hours, double charge)

{

return total_charge;

}

Explanation / Answer

The Modified program given below:

#include<stdio.h>
double total_charge(double h, double c);
void main()
{
double calc;
double hours,charge;
clrscr();
printf(" hours worked: ");
scanf("%ld", &hours);
printf("charges of cleaning per hour: ");
scanf("%ld", &charge);
calc = total_charge(hours,charge); //trying to call the function and ask for receive the value
printf("Total charge is %ld", calc);
getch();
}
double total_charge(double h,double c)
{
double tcharge;
tcharge=h*c;
return tcharge;
}

hi if you want to make read as a user defined function then u need to put hours and charge variables as global variables then only they can access in both main and read functions.then the code will be as follows:

#include<stdio.h>
double total_charge(double h, double c);

void read();

double hours,charge;
void main()
{
double calc;
clrscr();

read();
calc = total_charge(hours,charge); //trying to call the function and ask for receive the value
printf("Total charge is %ld", calc);
getch();
}

void read()

{

printf(" hours worked: ");
scanf("%ld", &hours);
printf("charges of cleaning per hour: ");
scanf("%ld", &charge);
}
double total_charge(double h,double c)
{
double tcharge;
tcharge=h*c;
return tcharge;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote