Loop makes switch's default option appear after any chosen case.

So I'm working on a c project. I had to make a loop that prompts the user to choose between 4 options. I chose the switch multi-way selection. Each option calls a function and appear some calculations to the user. There's one more option that would terminate the loop. I completed this. But there is one more thing that I have to include in the loop, and it's when the user enters any value other than the switch's cases' values, a message pops up saying "invalid value".
That message appears to the user after any option they choose. And when they do enter an invalid value, the message appears twice.
I tried placing that printf message in the switch's 'default', as well as by using if else. Same results.
I tried to change the whole switch multi-way selection to else..if. same results.

Here's the code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
  

for(scanf("%c", &letters); letters != 't'; scanf("%c", &letters))

       {
		
		switch (letters)   //switch between four options.
		{
		case 'A': 
		
			rtrnav = average(ages);
		    printf("\nThe average is: %.1f\n", rtrnav);
			continue;
		
		case 'M':
			
            rtrnmin = mini(ages);
			printf("\nThe minimum age is: %d\n", rtrnmin);
			continue;
			
		case 'X':
			    
				rtrnmax = maxi(ages);
				printf("\nThe maximum age is: %d\n", rtrnmax);
				continue;
			
		case 'S':
			
				rtrnsd = stndrd(ages);
				printf("\nThe Standard Deviation is: %.3f\n", rtrnsd);
				continue;
		default: printf("Invalid value\n");
		
		
		}
		}


everything works fine. The only problem I have is the "invalid value" message. I need it to appear only when the user enters an invalid value.

thanks in advance!!! :)
Topic archived. No new replies allowed.