Question:
The program should receive a sequence of numbers, if it receives the character S should stop and show the smallest number of them all. Thing is it doesn’t get in the loop, it shows the text to input/receive the variable for continuing excuting or stop, but it doesn’t wait for the inputed value and shows “Invalid value” instead. Would it be a problem about how the While and Switch commandas are declared? Sorry for the bad English, translated by myself.
Repl link:
#include <stdio.h>
#include <stdlib.h>
int main(void) {
int number = 0, Highest = 0, Smallest = 0, value = 1;
char termination;
printf("Choose the option below:\n");
printf("1-Enter with a sequence of numbers;\n");
printf("S-Close program up;\n");
termination = getchar();
while (termination != 'S') {
switch (termination) {
case '1':
{
printf("Input an integer value>0:\n");
scanf("%i", &number);
if (number < 0) {
printf("Invalid Value!\n");
termination = 'S';
value = 0;
} else {
if (value == 1) {
Smallest = number;
Highest = number;
}
value = 0;
if (number > Highest) {
Highest = number;
}
if (number < Smallest) {
Smallest = number;
}
printf("Choose the option below:\n");
printf("1-Enter with a sequence of numbers;\n");
printf("S-Close program up;\n");
termination = getchar();
}
}
break;
default:
printf("Invalid value!\n");
termination = 'S';
}
}
printf("The smallest number is:%i\n", Smallest);
printf("You ended this program up!");
return 0;
}