I have this program and I am not really sure on how to get it to close at the end.
Code:
#include <stdio.h>
#include <conio.h>
int newTotal = 0;
int input = 1;
int maxTotal = 0;
int week = 1;
void compute()
{
newTotal = input + newTotal;
}
void main()
{
int run;
printf ("Enter sales figures for the weeks.\nUse 0 to mark an end of a sales week and -1 to mark the end of all sales.\n");
for (run = 1; run!=0; )
{
scanf ("%d", &input);
if (input == 0)
{
printf("Week %d Sales: %d\n", week, newTotal);
if (newTotal > maxTotal)
maxTotal = newTotal;
week = week++;
newTotal = 0;
}
else if (input == -1)
{
printf ("Week %d Sales: %d\n", week, newTotal);
if (newTotal > maxTotal)
{
maxTotal = newTotal;
printf ("Max Week Sales: %d\n", maxTotal);
run = 0;
}
else
printf ("Max Week Sales: %d\n", maxTotal);
break;
}
else
compute();
}
printf ("\nPress any key to continue.\n");
getch();
}
Edit: The assignment forces me to use a for loop with a break. and we have to use void main()
Any help? Thanks