Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 22nd, 2008, 9:09 AM   #1
ifcaps(on):loop
Newbie
 
Join Date: Jun 2008
Posts: 3
Rep Power: 0 ifcaps(on):loop is on a distinguished road
syntax error before printf

I would appreciatee your help. It is written in C and is a pizza order form. It is very simple

{

     do printf ("Welcome and please follow instruction to order/n");
     printf ("enter your table number 1-25");  //---> it says syntax error before printf here
   
  scanf ("%d", tablenumber);
     if (tablenumber > 25); 
     return tablenumber;
    {
  ______________________________________
              {
                     bill = (6.50 + .50) *nopizzas;
                     printf ("your order will cost",bill); 
return 0;
}}}}}}
// C:\Users\Digit0ljedi\Desktop\sdgf\Makefile.win [Build Error] n\make.exe: *** ["order form.o"] Error 1 
//is this a a computer error or still code
thank you in advance
ifcaps(on):loop is offline   Reply With Quote
Old Jun 22nd, 2008, 10:36 AM   #2
Seif
Hobbyist Programmer
 
Seif's Avatar
 
Join Date: Jan 2006
Location: UK
Posts: 215
Rep Power: 3 Seif is on a distinguished road
Re: syntax error before printf

you have a stray do before the printf.
Seif is offline   Reply With Quote
Old Jun 22nd, 2008, 10:49 AM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
Re: syntax error before printf

and it's \n not /n
OpenLoop is offline   Reply With Quote
Old Jun 22nd, 2008, 10:56 AM   #4
ifcaps(on):loop
Newbie
 
Join Date: Jun 2008
Posts: 3
Rep Power: 0 ifcaps(on):loop is on a distinguished road
thank you

don't believe i missed that
ifcaps(on):loop is offline   Reply With Quote
Old Jul 2nd, 2008, 7:29 AM   #5
ifcaps(on):loop
Newbie
 
Join Date: Jun 2008
Posts: 3
Rep Power: 0 ifcaps(on):loop is on a distinguished road
Re: syntax error before printf

#include <stdio.h>
#include <stdlib.h>
#include <math.h>         

int main()        
{
int *tablenumber;
char *pizzabase;
char *pizza;
char *topping;
int *nopizza;
float bill;
float a = 0.50;
float b = 0.50;
float c = 3.50;
float d = 3.70;
float e = 4.00;
float f = 3.40;
float g = 0.75;
float h = 1.00;
float i = 0.45;

{
      
printf("|---------------------------------|\n");
printf("|Max shaws pizza ordering form    |\n");
printf("|25 June  Version 1.0             |\n");
printf("|---------------------------------|\n\n");


    {
                printf ("enter what pizza base you would like choose between\n");
                printf ("Thin and Crispy(a) or thick and cheesy(b)\n");
                do scanf("%c",&*pizzabase);
                while (*pizzabase==a);
                while (*pizzabase==b);
                
               
    {

                

printf ("please choose a pizza\n");
printf ("vegetarian (c), Meatfeast (d), Seafood (e), Cheese and Tomato (f)\n");
do scanf("%c",&*pizza);
while (*pizza==c);
while (*pizza==d);
while (*pizza==e);
while (*pizza==f);


{
      
       printf ("please choose an extra topping\n");
       printf ("anchovies (g), peppers (h), none (i)\n");
       do scanf("%c",&*topping);
       while (*topping==g);
       while (*topping==h);
       while (*topping==i);
       
       {
              printf ("how many pizzas wuold you like between 1 -10?");
              do scanf ("%d", &*nopizza);
              while (*nopizza >=11);
              while (*nopizza<=0);
              {
                     bill = (*pizzabase + *pizza + *topping) * *nopizza;
                     printf ("your order will \n"); 
                     printf("Total = %d",bill); 
                                          
                            {
system ("pause");
return *tablenumber;
return *pizzabase;
return *pizza;
return *topping;
return *nopizza;
return bill;
return 0;
}}}}}}}}

More help would be appreciated as everytime I run this it just closes down. comes up with a windows prompt. Im not sure where the problem is.
ifcaps(on):loop is offline   Reply With Quote
Old Jul 2nd, 2008, 11:47 AM   #6
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 644
Rep Power: 4 Jessehk is on a distinguished road
Re: syntax error before printf

There are two big problems with your code.

1) You have no notion of "standard" indenting and block practises so it is almost completely unreadable.

2) You have several misunderstandings of how the do-while loop works and how C in general works.

I was going to rewrite it for you, but I quickly became overwhelmed with the number of mistakes and logic errors. My advice would be to re-read whatever reference you're reading and if you'd like, I'm sure we could all make our own suggestions for recommended resources to help you out.


Maybe this will get you started. It's a simple example of a do-while loop. You shouldn't actually use the kind of code to read passwords, but
I think it's a nice example.

c Syntax (Toggle Plain Text)
  1. /* Simple do-while example.
  2.  *
  3.  * do-while loops are categorized by their behavior of
  4.  * always executing the body of the loop once before a condition
  5.  * is tested. If the condition listed at the end of the loop
  6.  * is evaluated to true, then the loop will continue. Otherwise,
  7.  * it will terminate.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. char *passwd = "apple";
  14.  
  15. #define BUFFSIZE 256
  16.  
  17. /* Ignore this function. It just removes the
  18.  * newline character read in by fgets from
  19.  * the string.
  20.  */
  21. char *chomp( char *str ) {
  22. char *end = str + strlen( str ) - 1;
  23.  
  24. if ( *end == '\n' )
  25. *end = '\0';
  26.  
  27. return str;
  28. }
  29.  
  30. int main( void ) {
  31. char buffer[BUFFSIZE];
  32.  
  33. /* The action that we want to occur regardless
  34.   * of the condition is the prompt for the password
  35.   * and the actual retrieval of the password.
  36.   * Next, once we have it, we compare
  37.   * the input to the know password above ("apple");
  38.   * If the passwords match (and strcmp() returns 0
  39.   * when the strings it is comparing are equivalent),
  40.   * then the condition will evaluate to false
  41.   * and the loop will continue. Otherwise, strcmp()
  42.   * will return a value either greater than 1 or
  43.   * less than -1 (both of which evaluate to true),
  44.   * and the loop will continue again and re-ask for
  45.   * the password.
  46.   */
  47. do {
  48. printf( "password: " );
  49. fgets( buffer, BUFFSIZE, stdin );
  50. } while ( strcmp( chomp( buffer ), passwd ) );
  51.  
  52. puts( "Password accepted. Welcome 007" );
  53. return 0;
  54. }

If you have any questions, don't be afraid to ask.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!

Last edited by Jessehk; Jul 2nd, 2008 at 12:07 PM.
Jessehk is offline   Reply With Quote
Old Aug 8th, 2008, 1:48 PM   #7
rhish.franks
Programmer
 
Join Date: Feb 2008
Location: India
Posts: 58
Rep Power: 1 rhish.franks is on a distinguished road
Re: syntax error before printf

Would like to say same as said by jessehk. And also would like to say that start using arrays instead of defining those all floats from a to i. float a[] = {0.5,0.5,3.5,3.75,......};
rhish.franks is offline   Reply With Quote
Old Aug 13th, 2008, 10:49 PM   #8
Echo
Newbie
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0 Echo is on a distinguished road
Re: syntax error before printf

Quote:
Originally Posted by Jessehk View Post
There are two big problems with your code.

1) You have no notion of "standard" indenting and block practises so it is almost completely unreadable.

2) You have several misunderstandings of how the do-while loop works and how C in general works.

I was going to rewrite it for you, but I quickly became overwhelmed with the number of mistakes and logic errors. My advice would be to re-read whatever reference you're reading and if you'd like, I'm sure we could all make our own suggestions for recommended resources to help you out.


Maybe this will get you started. It's a simple example of a do-while loop. You shouldn't actually use the kind of code to read passwords, but
I think it's a nice example.

c Syntax (Toggle Plain Text)
  1. /* Simple do-while example.
  2.  *
  3.  * do-while loops are categorized by their behavior of
  4.  * always executing the body of the loop once before a condition
  5.  * is tested. If the condition listed at the end of the loop
  6.  * is evaluated to true, then the loop will continue. Otherwise,
  7.  * it will terminate.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <string.h>
  12.  
  13. char *passwd = "apple";
  14.  
  15. #define BUFFSIZE 256
  16.  
  17. /* Ignore this function. It just removes the
  18.  * newline character read in by fgets from
  19.  * the string.
  20.  */
  21. char *chomp( char *str ) {
  22. char *end = str + strlen( str ) - 1;
  23.  
  24. if ( *end == '\n' )
  25. *end = '\0';
  26.  
  27. return str;
  28. }
  29.  
  30. int main( void ) {
  31. char buffer[BUFFSIZE];
  32.  
  33. /* The action that we want to occur regardless
  34.   * of the condition is the prompt for the password
  35.   * and the actual retrieval of the password.
  36.   * Next, once we have it, we compare
  37.   * the input to the know password above ("apple");
  38.   * If the passwords match (and strcmp() returns 0
  39.   * when the strings it is comparing are equivalent),
  40.   * then the condition will evaluate to false
  41.   * and the loop will continue. Otherwise, strcmp()
  42.   * will return a value either greater than 1 or
  43.   * less than -1 (both of which evaluate to true),
  44.   * and the loop will continue again and re-ask for
  45.   * the password.
  46.   */
  47. do {
  48. printf( "password: " );
  49. fgets( buffer, BUFFSIZE, stdin );
  50. } while ( strcmp( chomp( buffer ), passwd ) );
  51.  
  52. puts( "Password accepted. Welcome 007" );
  53. return 0;
  54. }

If you have any questions, don't be afraid to ask.
And if fgets() returns NULL?
__________________
http://www.echo.net84.net/
Echo is offline   Reply With Quote
Old Aug 13th, 2008, 11:10 PM   #9
lectricpharaoh
Caffeinated Neural Net
 
lectricpharaoh's Avatar
 
Join Date: Jun 2005
Location: Dry west coast of Canada
Posts: 1,034
Rep Power: 5 lectricpharaoh will become famous soon enough
Re: syntax error before printf

Quote:
Originally Posted by Echo
And if fgets() returns NULL?
Perhaps you didn't read all of Jessehk's post, and missed this:
Quote:
Originally Posted by Jessehk
It's a simple example of a do-while loop. You shouldn't actually use the kind of code to read passwords, but I think it's a nice example.
This makes it pretty clear it's intended as an example, and not to be taken literally. In particular, error-handling logic is often omitted from trivial examples to simplify things and cut down on typing. This should not be construed as advocating that error-handling logic should be avoided.

Besides, fgets() only returns NULL for error conditions unrelated to user input, such as not being able to read from the stream (unlikely for stdin), whereas scanf() will fail to read data in the wrong format. If you're going to complain about Jessehk not checking for NULL, then you'd better complain about your failure to check scanf()'s return value (which, for the record, is a count of items successfully converted, or EOF on error).
__________________
And once again, Probability proves itself willing to sneak into a back alley and service Drama as would a copper-piece harlot.
- Vaarsuvius, Order of the Stick
lectricpharaoh is offline   Reply With Quote
Old Aug 14th, 2008, 4:14 PM   #10
Echo
Newbie
 
Join Date: Aug 2008
Posts: 5
Rep Power: 0 Echo is on a distinguished road
Re: syntax error before printf

Right... I don't see scanf() being used in Jessehk's code at all. Besides error checking is always important and I was just trying to make a point that its important to instill good practices.
__________________
http://www.echo.net84.net/
Echo is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
printf Alignment Sane C 13 Jan 27th, 2008 8:18 PM
syntax error in Mysql... ktsirig PHP 1 Feb 3rd, 2007 1:30 PM
Header file internal errors kruptof Coder's Corner Lounge 2 Jan 14th, 2007 1:12 PM
From C syntax to C++ syntax Navid C++ 13 Jan 15th, 2006 7:42 AM
How to say the size of an array using printf ? colt C 2 May 19th, 2005 3:25 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:59 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC