I’m not sure why it’s saying it’s not initialized, I clearly did with, that, char typeOfWash, tireShine; line, right? My code works just fine as long as the input isn’t ‘g’,’G’,’p’, or ‘P’. I haven’t put in the last case for if typeOfWash == anything else then print “invalid selection”, but that’s easy and I’ll drop that in later.
#include <stdio.h>
int main()
{
//variable declarations
char typeOfWash, tireShine;
//Menu
printf("R ---> Regular ($5.00)\n");
printf("B ---> Bronze ($7.50)\n");
printf("G ---> Gold ($10.25)\n");
printf("P ---> Platinum ($15.00)\n");
printf("Tire Shine can be added to the Gold or Platinum ONLY,");
printf("for an additional$2.50\n\n");
printf("Enter your selection: ");
scanf("%c",&typeOfWash);
switch (typeOfWash)
{
case 'R': case 'r':
printf("Your bill total is: $5.00\n");
break;
case 'B': case 'b':
printf("Your bill total is: $7.50\n");
break;
case 'G': case 'g':
printf("Would you Like a Tire Shine? (Y/N): ");
scanf("%c",tireShine);
if (tireShine == 'Y' || tireShine == 'y')
printf("Your bill total is: $12.75");
else
printf("Your bill total is: $10.25");
break;
case 'P': case 'p':
printf("Would you Like a Tire Shine? (Y/N): ");
scanf("%c",tireShine);
if (tireShine == 'Y' || tireShine == 'y')
printf("Your bill total is: $17.50");
else
printf("Your bill total is: $15.00");
break;
}
return 0;
}
You need to change:
to:
(in two places). Reason:
scanf(and C functions in general) need a pointer to any variable that are going to be modified.It’s also good practice (defensive programming) to explicitly initialise your variables, e.g. change:
to: