# scanf question

• 03-22-2009
hockey1
scanf question
alright my program needs to prompt the user how many circles between 1 and 10 they would like to calculate circumference and area of. then the user enters a number between 1 and 10 or the program prints an error message.
however, if a correct number is entered, it then begins to prompt the user to enter the radius for each circle and stores them in an array to do the required calculations.

lets say you want to use 4 circles.
the problem is that its printing the prompt message:

"Enter the radius for circle #1:"

"Enter the radius for circle #2"

"Enter the radius for circle #3:"

"Enter the radius for circle #4:"

*then down here it allows you to enter the radius'*

i need it to prompt like this:

"Enter the radius for circle #1:"
"Enter the radius for circle #2:"
"Enter the radius for circle #3:"
"Enter the radius for circle #4:"

any ideas?
*please keep in mind im working on this and its not nearly completed yet, i just like to compile and test along the way so i dont get a million errors at the end to deal with.

Code:

```#include <stdio.h> main () {         int circleno;         int imputvalues[10], i;         int j;         printf("Please enter the number of circles (max = 10):\n");         scanf("%i", &circleno);         if (circleno < 1 || circleno > 10)                 printf("Error -> %i circles is too many. Please try again:\n", circleno);                 else                 printf("You have selected to enter %i circles.\n\n", circleno);                 for ( j = 1; j <= circleno; ++j )                         printf("Enter the radius for circle #%i:\n\n", j);                         scanf("%i", &imputvalues[i]);                                         return 0; }```
i appreciate the help guys and gals!
• 03-22-2009
Nightowl
Well, something to consider is that you will want that code in a loop of sorts, such as . . .

(pseudocode, not real C!)
Code:

```first = 1 do {     if(!first) explain_error()     print_prompt()     get_data()     first = 0 } while(invalid_input)```
Or so.

Does that make any sense?

Note that this applies to your # of circles data entry as well as the circle radius entry.