Hi, I'm new here and relatively new to the C language.
Anyway I'll get straight to the point.
I'm working on an assignment ( no I am not asking anyone to help me complete it), it is basically a Launderette system and I'm encountering a slight problem when i tried to use pointers.
The program stopped working at a certain point which i commented.
Here is the coding:
Code:
....
float handWash(){
int numOfHWash;
float hWashTotal;
float price_hWash = 5;
printf("\nEach item hand washed will be RM%.2f", price_hWash);
printf("\n\nEnter number of clothes to be hand washed: ");
scanf("%d", &numOfHWash);
hWashTotal = numOfHWash*price_hWash;
serviceType(&hWashTotal);
printf("\n\nThe total cost is: RM%.2f", hWashTotal);
}
....
void serviceType(float *svcCost){
int sType_input;
printf("\n\n");
printf("1. Regular Service: 30%% Discount.\n");
printf("2. Express Service: 50%% Extra Charge.\n");
printf("Enter the service type: ");
scanf("%d", sType_input);
//the program stopped working after receiving the input
if(sType_input == 1)
*svcCost = *svcCost * 0.7;
else
*svcCost = *svcCost * 1.5;
}
So after I entered 1 or 2, a little window would pop up saying the program would stop working.
I tried removing the scanf() and leaving only one statement.
The program when I did and I could work around it to make it so but I want to know why and hoping that there might be a solution to this?
Perhaps any advice?
Thanks in advance and sorry if I broke any rules