How to optimise this c program?
Code:
#include <stdio.h>
void main(void)
{
/* ================================== Local Definitions ================================== */
/*Declare a variable for Sales Agent's code number*/
int num;
/*Declare variables for sales amount for week 1,2,3,4 , total sales
and the commission earned*/
double week1, week2, week3, week4, sum, earn;
start:
/* Statements */
printf("Please key in Sales Agent's code number>");/* Output statement*/
scanf("%d", &num);/* Input statement*/
fflush(stdin);
{
if(num>=1000&&num<=9999)/* Define maximum 4 digits for Sales Agent's code number */
goto next;
else {
printf("Invalid code number! Please key in 4 digits code number.\n");
goto start;
}
}
next:
printf("\nPlease key in sales amount for Week 1 (RM)> ");
/* Output statement*/
scanf("%lf", &week1);
/* Input statement*/
fflush(stdin); /* flush the "enter" or other unrelated characters in the memory */
printf("\nPlease key in sales amount for Week 2 (RM)> ");
/* Output statement2*/
scanf("%lf", &week2);
/* Input statement*/
fflush(stdin);
printf("\nPlease key in sales amount for Week 3 (RM)> ");/* Output statement*/
scanf("%lf", &week3); /* Input statement*/
fflush(stdin);
printf("\nPlease key in sales amount for Week 4 (RM)> "); /* Output statement*/
scanf("%lf", &week4); /* Input statement*/
sum= week1 + week2 + week3 + week4;/* Formula for total sales */
printf("\nTotal sales in a month: RM %.2lf", sum);/* Output statement*/
earn= sum *.2; /* Formula for commission earned */
printf("\n\nCommission earned: RM %.2lf\n\n", earn);/* Output statement*/
printf("Press Any Key to continue");
getch(); /* Waiting for any key press to exit the program */
}