Hello,
This is my first post to the forum, I have a question regarding the scanf function. My program seems to find a random value to use on the second scanf call in my program. I'm using scanf with a char on both occasions. It does not ask for user input on the second scanf function. How can I fix this, do I have to use something else than scanf?
Here is my simple code so far:
Code:
#include <stdio.h>
#include <stdlib.h>
int package_i;
char internet, package, phone;
float cost;
main () {
printf("Welcome to XYZ Cable Providers\nWould you like to subscribe to Internet? (Y or N): ");
scanf("%c", &internet);
if (internet == 'Y') {
printf("Choose package 1, 2, or 3: ");
scanf("%d", &package_i);
switch (package_i) {
case 1:
cost = 15.99;
break;
case 2:
cost = 21.99;
break;
case 3:
cost = 25.99;
break;
default:
break;
}
}
printf("Your total cost is %.2f!", cost);
printf("Would you like to subscribe to Home Telephone? (Y or N): ");
scanf("%c", phone);
}
Thanks for the help,
Matthew