Code: #include <stdio.h> int main(){ char name[8]; char ordername[8]; int ordernumber=0; float bill=0; printf("Enter X for exit"); do{ printf(" ordernumber: &s bill: &f", ordernumber, bill); printf("Enter your name: /n"); scanf(" %s", name); printf("Enter your order (Pizza: 2$ Burger: 3$)"); scanf(" %s", ordername); if(order == 'Pizza'){ bill = 2; }else{ bill = 3; } ordernumber++; }while(ordername != 'X'); return 0; }
Code: Line 1: error: invalid preprocessing directive #� In function 'main': Line 18: error: 'order' undeclared (first use in this function) Line 18: error: (Each undeclared identifier is reported only once Line 18: error: for each function it appears in.) Line 12: warning: character constant too long for its type Line 27: warning: comparison between pointer and integer
I'm not sure what the error is about on line 1. Looks fine to me. The variable "order" is undeclared, perhaps you meant to use "ordername" instead? And that is not how you do string comparison in C. First, strings are embedded in "double quotes". The reason for the errors about integers is that a character, or escape sequence, enclosed in 'single quotes' is a single char and is effectively an integer constant; for example 'A' means exactly the same as 65, if you're using ASCII. To compare strings you need to use the strcmp function, which returns zero if the strings are equal. Code: if (!strcmp(ordername, "Pizza")) should fix a few of those errors.