Jump to content

Need help with Programming Logic.


gaza165

Recommended Posts

what i am trying to do, is accept numbers from users and store them into an array. as soon as a user enters a negative number i want the program to break and calculate the average of those numbers and display it.

 

as you can see, i have an if function inside my for loop to check if the number is below 0 then to break. am i doing this right or is my logic messy?

 

should i have used a while loop or a do while!!

 

     for(i=0; ; i++)
 {
      printf("%2d> ",i+1);
      scanf("%d", &numbers[i]);
  if(numbers[i] < 0) { break; }
  sum += numbers[i];
  count = i + 1;	  
 }

 

Link to comment
https://forums.phpfreaks.com/topic/145553-need-help-with-programming-logic/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.