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.


Recommended Answers

All 2 Replies

>>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);
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.