// Этот код должен добавлять или вычитать и отслеживать четыре разных марки пива с индивидуальными идентификаторами. Использование -1 завершает работу, но с использованием любого из идентификационных номеров 1-4 заставляет программу выполнять дело defualt.Оператор Switch продолжает использовать случай по умолчанию независимо от того, что - C beginner
#include <stdio.h>
int main(){
int inv1;
int inv2;
int inv3;
int inv4;
printf("Pleas enter the beginning inventory of Piels. \n");
scanf("%d", &inv1);
printf("Pleas enter the beginning inventory of Coors. \n");
scanf("%d", &inv2);
printf("Pleas enter the beginning inventory of Bud. \n");
scanf("%d", &inv3);
printf("Pleas enter the beginning inventory of Iron City. \n");
scanf("%d", &inv4);
printf("Please enter the ID number. \n Piels - 1 \n Coors - 2 \n Bud - 3 \n Iron City - 4 \n Enter -1 to exit \n");
int id;
scanf("%d", &id);
while(id != -1){
int amount;
switch (id) {
case '1':
printf("Enter the change in amount. It will be a negative if the amount is sold, or positive if the amount is purchased \n");
scanf("%d", &amount);
inv1 += amount;
break;
case '2':
printf("Enter the change in amount. It will be a negative if the amount is sold, or positive if the amount is purchased \n");
scanf("%d", &amount);
inv2 += amount;
break;
case '3':
printf("Enter the change in amount. It will be a negative if the amount is sold, or positive if the amount is purchased \n");
scanf("%d", &amount);
inv3 += amount;
break;
case '4':
printf("Enter the change in amount. It will be a negative if the amount is sold, or positive if the amount is purchased \n");
scanf("%d", &amount);
inv4 += amount;
break;
default:
printf("Error: That ID Number is not an option. \n");
break;
}
printf("Please enter the ID number. \n Piels - 1 \n Coors - 2 \n Bud - 3 \n Iron City - 4 \n Enter -1 to exit \n");
scanf("%d", &id);
}
return 0;
}
Я не хорошо разбираюсь в C, но не 'id' должен быть' int'? ваши 'case' заключены в одинарные кавычки – jmcg
для удобства понимания и удобочитаемости нами людей: 1) последовательно отступать от кода (никогда не используйте вкладки для отступов, так как каждый текстовый процессор/редактор имеет ширину табуляции/ширину закладки по-разному.) Отступ после каждой открытой скобки '{'. Un-indent перед каждой закрывающей скобкой '}'. Предложите использовать 4 пробела для каждого уровня отступа, поскольку 4 пространства достаточно широки, чтобы быть видимыми даже с изменяемыми ширинами шрифтов. 2) следовать аксиоме: * только один оператор в строке и (самое большее) одно объявление переменной для каждого оператора. * 3) отдельные блоки кода (для if, else, while. Do ... while, switch, case, default) по пустой строке. – user3629249
маленькая вещь: слово «просьбы» неизвестно, подозревая, что вы имели в виду «пожалуйста». – user3629249