What are the errors in this program? /* This program uses a function to read thr
ID: 3531508 • Letter: W
Question
What are the errors in this program?
/* This program uses a function to read three integer values and uses another function to compute and print their average to two decimal digits i.e. in the form 999.99 */
#include<stdio.h>
void readData (int no1, int no2, int no3 ) ;
int main(void)
{ int n1, n2, n3
// a function call to the function readData to read the numbers.
readData(n1, n2, &n3) ;
//function call to the function to compute and print the average.
computeAverage(n1, n2, n3);
return ;
}
int readData (int* no1, int no2, int no3 )
printf(" Please enter an integer ") ;
scanf_s("%d",n1) ;
printf(" Please enter an integer ") ;
scanf_s("%d",&n2) ;
printf(" Please enter an integer ") ;
scanf_s("%d",&n3) ;
}
void computeAverage(int no1, int no2, int no3) ;
{ float average ;
sum = no1 + no2 + no3 ;
average = sum / 3 ;
printf(" The numbers are: %d , %d ",no1, no2, no3);
printf(" average is: %f", average ) ;
}
Explanation / Answer
/*
error is on lineintreadData (int* no1,intno2,intno3 )
you should pass all three arguments by reference so that any change in value is reflected
so it should beintreadData (int* no1,int*no2,int*no3 )
now correct program is
also there were few ; missing here and there
Here is complete program compiled in dev c++
*/
#include<stdio.h>
int readData (int *no1, int *no2, int *no3 );
void computeAverage(int no1, int no2, int no3) ;
int main(void)
{ int n1, n2, n3;
// a function call to the function readData to read the numbers.
readData(&n1, &n2, &n3) ;
//function call to the function to compute and print the average.
computeAverage(n1, n2, n3);
return ;
}
int readData (int *n1, int *n2, int *n3 ){
printf(" Please enter an integer ") ;
scanf("%d",&n1) ;
printf(" Please enter an integer ") ;
scanf("%d",&n2) ;
printf(" Please enter an integer ") ;
scanf("%d",&n3) ;
}
void computeAverage(int no1, int no2, int no3)
{
float average ;
int sum = no1 + no2 + no3 ;
average = sum / 3 ;
printf(" The numbers are: %d , %d ",no1, no2, no3);
printf(" average is: %f", average ) ;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.