0

attached is the q of the c program....and
here's what i try to write out...
may i know how should i write to prompt user to enter the four weights from the keyboard. and the program should print an error message if the weights are out of range?

Here's my program

#include<sdtio.h>
floatx[4] = {1.2,2.4,3.6,4.8};
float f[4] = {0.1,0.2,0.3,0.4};


main()

{

int i;
for (i=0; 1<4;i++) ftotal+ = f;
if(ftotal!=1.0)
{
printf("error\n");
exit();
}
for(i=0;1<4;i++) xave+=f *x;
printf("\nThe weights are %f"&f);
printf("\nThe average is %f\n",xave);

please advise me. Thanks.


Attachments q1.JPG 122.65 KB
3
Contributors
2
Replies
3
Views
11 Years
Discussion Span
Last Post by Ancient Dragon
0

>>may i know how should i write to prompt user to enter the four weights from the keyboard.

just create a loop for this

int i;
float weights[4] = {0};
char buf[80];
for(i = 0; i < 4; ++i)
{
   printf("Enter weight #%d", i+1);
   fgets(buf,sizeof(buf),stdin);
   weights[i] = atof(buf);
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.