Программа проста:C: Не могу найти ошибку [Do-While цикл]
1) Он принимает имя пользователя 2) Спрашивает, сколько элементов он купил и сколько это стоит 3) если входы ничего> 10 элементов, он говорит: «Пожалуйста, введите число больше 0 (ноль) и менее 10 (десять). Вы хотите продолжить генерировать другой счет? (Y/N)» 4) Пользователь вводит «Y», он должен взять его в начало цикла do и начать все заново.
Все в порядке работает нормально. Вот код:
int main()
{
char item[10][10], answer = 'null', name[10];
int price[10], total_item, total_price = 0, i, j = 0, a;
float service_tax = 0, vat = 0,total_bill = 0, bill = 0;
printf ("Please enter your name: ");
scanf ("%s", name);
do
{
printf ("\n Enter the total items purchased (must be more than 0 (zero) and less than 10 (ten): ");
scanf (" %d", &total_item);
if(total_item > 0 && total_item <= 10)
{
for(i = 0; i < total_item; i++)
{
printf ("\nEnter the item name: ");
scanf ("%s", item[i]);
printf ("\nEnter the item price: ");
scanf ("%d", &price[i]);
bill = bill + price[i];
}
printf("You bill WITHOUT the tax is: %f \n", bill);
service_tax = ((bill * 10)/100);
vat = ((bill * 12)/100);
total_bill = service_tax + vat + bill;
printf("The items you've purchased are: \n");
for(i = 0; i < total_item; i++)
{
printf("\n%s - %d\n", item[i], price[i]);
}
printf("Your total bill is: %3f", total_bill);
printf ("Your bill# is %s-%d-%d", &name, total_item, rand()%1000);
}
else
{
printf("\n %s, please enter a number greater than 0 (zero) and less than 10 (ten)", &name);
printf("\nDo you want to continue generating another bill? (Y/N)\n");
scanf (" %c", &answer);
}
}while ((answer == 'y') || (answer = 'Y'));
return 0;}
Пожалуйста, ПОМОГИТЕ ПОМОЧЬ МЕНЯ! Для моей жизни я не могу понять, почему цикл do-while не работает.
Вы помогаете с пониманием!
ответ = 'Y' изменить на ответ == 'Y' – sashkello
'answer = 'Y'' в предложении' while' является подозрительным, вы имели в виду 'ответ ==' Y ' '? – Teetoo