can you please correct the mistake i want main to receive a value (total charge
ID: 3581045 • 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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.