Useing Xcode I keep getting an error for executable runner: program has exited due to signal 10(SIGBUS).
This happens anytime I try to input a choice from the menu, so I dont think the code is running the switch statement correctly but I cant find anything wrong with it. Any help would be greatly appreciated.
Code:
#include <stdio.h>
int main (void)
{/*main*/
int avg, choice=1, num, sum=0, i, num_max=0;
while(choice>=1 && choice<=5)
{/* while */
printf("Please choose one of the following\n");
printf("1. Find the average\n");
printf("2. Find the largest\n");
printf("3. Exit\n");
scanf("%d", choice);
switch(choice)
{/*switch*/
case 1:/*find average */
i=0;
while(i<10)
{/*while*/
printf("Enter number:");
scanf("%d",num);
sum=sum+num;
i=i+1;
}/*while close*/
avg=sum/10;
printf("The average of the numbers is: %d\n", avg);
break;
case 2: /*find max*/
i=0;
while(i<10)
{/*while*/
printf("Enter number:");
scanf("%d",num);
if(num>num_max)
num_max=num;
i=i+1;
}/*while close*/
printf("The largest value is: %d\n", num_max);
break;
case 3:
printf("Exiting");
break;
default:
printf("Error");
break;
}/*end switch*/
}/*end while*/
return(0);
}/*end main*/