I'm currently trying to make a number pseudo calculator of sorts that is supposed to add any number of integers until a negative is given then sum the amount of integers added, the biggest, smallest, average and also count the numbers of integers given. I have managed to make all of that, now im supposed to loop it without using a infinite loop, i have tried several hours but i just cant figure it out. I tried making the code return to the start but that doesn't seem to work. I'm wondering if it's possible to make the code return to the start or if another way to make it loop exist.
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int number = 0;
int big = -1;
int small = -1;
float average = 0;
int sum = 0;
int counter = 0;
do
{
printf("Enter a number: ");
scanf_s("%d", &number);
if (number < 0)
break;
sum += number;
if (big == -1 || number > big)
{
big = number;
}
if (small == -1 || number < small)
{
small = number;
}
counter++;
average = (float) sum / counter;
printf("sum =%d, big = %d, small = %d, counter = %d", sum, big, small, counter);
printf("average = %.2f", average);
} while (number >= 0);
int yes = 1;
int no = 0;
printf("Would you like to run the program again (1 for yes, 0 for no)?: ");
scanf_s("%d, %d", &yes, &no);
if (yes == 1 || no != 1)
{
goto main;
}
else
return 0;
}