Hi everyone, almost done with my code here but for some reason when the user enters 'Y' it does not loop up back to the top of the code. This is very important for me because I need it to display the count of sales. Any idea why? The do-while loop is being used. Here is my code:
Code:
#include <stdio.h>
#define COMPANY "company"
#define MAXA 1000000
#define MINA 10000
#define MINCP 0
#define MAXCP 6
void report(int sale, double cp, double tc);
int getAmount(int min, int max, char item[]);
double calcAmount(int sale, double cp);
main()
{
int i=0;
int sale, ch;
double cp, tc;
char c;
do
{
system("cls");
printf("\n\n\t%s\n\n", COMPANY);
sale = getAmount(MINA, MAXA, "home sale amount");
cp = getAmount(MINCP, MAXCP, "commission percentage");
tc = calcAmount(sale, cp);
report(sale, cp, tc);
i++;
printf("\tContinue (Y/N) : ");
scanf("%c%*c", &c);
} while(c == 'y' || c == 'Y');
printf("\n\tTotal count:", i);
return 0;
}
void report(int sale, double cp, double tc)
{
printf("\n\tThe home price is %6.2d",sale);
printf("\n\tThe commission percentage is %2.1f", cp);
printf("\n\tThe commission is %4.2f", tc);
}
int getAmount(int min, int max, char item[])
{
int n;
printf("\n\tEnter the %s from %d to %d: ", item, min, max);
scanf("%d*c*",&n);
while (n < min || n > max)
{
printf("\n\tError, please enter within range");
printf("\n\tEnter the %s from %d to %d: ", item, min, max);
scanf("%d*c*",&n);
}
return (n);
}
double calcAmount(int sale, double cp)
{
return (sale * (cp / 100));
}
I think it has something to do with the subfunctions I believe...I am really stumped on this one..
help would be greatly appreciated..thanks
Also sorry for not including comments, i usually do this at the last moment :\