Hello, full disclosure this is for a homework assignment for my C programming class and any help would be greatly appreciated!
So I have to set up a program specifying certain packages for a cruise line, inputting number of passengers and their ages with possible discounts for minors. However, I'm having trouble starting the code, because I can't find the right combination of getchar(), or scanf(%d,&variable) that allows the user to input a character, leading them to the right part of the program that applies to them. For instance, I'd like the user to input R or M, depending on whether they want the room or the room and meal package. They input the variable, and that sets my x value equal to R or M, leading them down the right if and else codes. They input R, so I want different things to happen than if they inputted M. Is there an easier way to do this than the code I set up below? If not, how do I use a user inputted variable to direct where my code goes? In the example I posted, the code always returns "failed", and I am trying to get it to return number of passengers.
Code:
#include <stdio.h>
//, Homework 1, Question 8
int main()
{
int R, M;
int p;
int c;
int x;
printf("Enter R for room package\nEnter M for room plus meals package\n");
x = getchar();
getchar(); //this line is so enter wont count as a character.
if ( x == R )
{
printf("Number of passengers?\n");
}
else
{
printf("failed");
}
return 0;
}