I'm very new to programming (so I apologize in advance), and I am having trouble figuring out how to make a for loop that will do the following:
I'm asking the user to input two variables (i'll call them x & y), which I then am calculating x/y = z. I want to pose this two variable input question 3 times, and then add up the 3 z to find the average. (The later part about accumulating/averaging I can figure out, but getting a for loop to repeat and give z three times is stumping my extremely novice mind. So far I can only get the for loop to ask for the two variable inputs one time, spit out z, and then terminate (I haven't attempted the averaging of z yet, because I don't have more than one z at this time).
To make things clearer, here's what I've got (user prompts to be more clearly developed later, just looking for for loop solving here, not prompt critique ):
Code:
I'm very new to programming (so I apologize in advance), and I am having trouble figuring out how to make a for loop that will do the following:
I'm asking the user to input two variables (i'll call them x & y), which I then am calculating x/y = z. I want to pose this two variable input question 3 times, and then add up the 3 z to find the average. (The later part about accumulating/averaging I can figure out, but getting a for loop to repeat and give z three times is stumping my extremely novice mind. So far I can only get the for loop to ask for the two variable inputs one time, spit out z, and then terminate (I haven't attempted the averaging of z yet, because I don't have more than one z at this time).
To make things clearer, here's what I've got (user prompts to be more clearly developed later, just looking for for loop solving here, not prompt critique :) ):
includeint main(void) {
float x, y, z;
char c;
printf ("Enter x: ");
scanf ("%f",&x);
while((c = getchar()!='\n')&& c != EOF);
printf ("Enter y: ");
scanf ("%f",&y);
while((c = getchar()!='\n')&& c != EOF);
for(x, y; x <=1; x++)
{
z = x / y;
printf("Your average is %f\n", z);
}
printf("Thank you for using the program. Goodbye\n");
getchar();
return0;
}Thanks for your help!!
Thanks for your help!!