Solution For Your Problem
The problem is that your variables A, B, C, D, S, M, L are of type char. A char is an integral type taking value in a range of [-128, 127]. These variables are supposed to represent the price of a certain food.
When you assign A = 150, then the actual value stored in A is -106 as it overflows (128 - 150 = 22 overflow, hence -128 - 22 = -106). Similarly, when you add to chars together the chances are that you cannot store the result on just one signed byte (char). Instead, use a larger type, e.g. int.
And Some Extra...
You could restructure your code in a way that data and logic is separated. You could create functions that deal with processing various food requests or displaying them. You could create a data structure that holds the code, the name and the price of a specific food item.
If you do this, your program is easily extendable. If you want to add a new meal or drink, you just add it to the right array and voila, everything works. No need to touch anything else, no extra switch-cases, no extra logic needed.
See an example for this below:
#include <ctype.h>
#include <stdio.h>
#define CODE_LENGTH 8
#define NAME_LENGTH 24
#define PRICE_LEN 8
#define ElementCount(array) sizeof(array) / sizeof(array[0])
typedef struct
{
char code;
const char * name;
int price;
} Food;
// columns must have exactly 3 elements
void PrintHeader(const char ** columns)
{
printf("%-*s%-*s%*s\n", CODE_LENGTH, columns[0], NAME_LENGTH, columns[1], PRICE_LEN, columns[2]);
}
void PrintFood(const Food * foods, size_t numFoods)
{
for (size_t i = 0; i < numFoods; i++)
printf("%-*c%-*s%*d\n", CODE_LENGTH, foods[i].code, NAME_LENGTH, foods[i].name, PRICE_LEN, foods[i].price);
}
const Food * Find(const Food * foods, size_t numFoods, char code)
{
for (size_t i = 0; i < numFoods; i++)
{
const Food * food = &foods[i];
if (food->code == code)
return food;
}
return NULL;
}
int main()
{
//
// Setting up the menu
//
const char * mealHeader[] = { "Meal", "Package", "Price" };
Food meals[] =
{
{ 'A', "Chicken & Spaghetti", 150 },
{ 'B', "Hamburger & Fries", 145 },
{ 'C', "Cheese Burger", 100 },
{ 'D', "Pizza", 80 }
};
const char * drinkHeader[] = { "Drinks", "Description", "Price" };
Food drinks[] =
{
{ 'S', "Small Drinks", 30 },
{ 'M', "Medium Drinks", 35 },
{ 'L', "Large Drinks", 40 }
};
//
// Printing the menu
//
PrintHeader(mealHeader);
PrintFood(meals, ElementCount(meals));
printf("\n");
PrintHeader(mealHeader);
PrintFood(drinks, ElementCount(drinks));
printf("\n");
//
// Asking the user to choose something from the menu
//
char meal;
char drink;
int quantity;
printf("Enter your meal (A, B, C, D, E) : ");
scanf("%c", &meal);
printf("Enter your drink (S, M, L) : ");
scanf(" %c", &drink);
printf("Quantity : ");
scanf(" %d", &quantity);
printf("\n");
printf("--------------------------------------------")
printf("\n");
//
// Processing the user's choice
//
const Food * orderedMeal = Find(meals, ElementCount(meals), toupper(meal));
if (!orderedMeal)
{
printf("Invalid meal code: %c\n", meal);
return -1;
}
const Food * orderedDrink = Find(drinks, ElementCount(drinks), toupper(drink));
if (!orderedDrink)
{
printf("Invalid drink code: %c\n", drink);
return -1;
}
int total = (orderedMeal->price + orderedDrink->price) * quantity;
printf("Meal : %c\n", meal);
printf("Drink : %c\n", drink);
printf("Quantity : %d\n", quantity);
printf("Order details: %s and %s\n", orderedMeal->name, orderedDrink->name);
printf("Amount : %d", total);
return 0;
}