Thread: Codeblocks gives me error message for writing code from book, please look.

  1. #1
    Registered User
    Join Date
    Dec 2019
    Posts
    99

    Codeblocks gives me error message for writing code from book, please look.

    Here is the code:
    Code:
    #include <stdio.h>
    
    
    {
    
    
    main()
    //my variable for the program
    
    
    char firstInitial, middleInitial;
    int number_of_pencils;
    int number_of_notebooks;
    float pencils = 0.23;
    float notebooks = 2.89;
    float lunchbox = 4.99;
    
    
    //information for first child
    firstInitial = 'J';
    middleInitial = 'R';
    
    
    number_of_pencils= 6;
    number_of_notebooks= 4;
    
    
    printf ("%c%c needs %d pencils, %d notebooks, and 1 lunch box\n", firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
    printf("The total cost is $%.2f\n\n", number_of_pencils*pencils + number_of_notebooks*notebooks + lunchbox);
    
    
    //Information for 2nd child
    
    
    firstInitial = 'A';
    middleInitial = 'J';
    
    
    number_of_pencils = 10;
    number_of_notebooks = 3;
    
    
    printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n", firstInitial, middleInitial, number_of_pencils*pencils + number_of_notebooks*notebooks" + lunchbox);
    
    
    //infor for third child
    
    
    firstInitial = 'M';
    middleInitial = 'T';
    
    
    number_of_pencils = 9;
    number_of_notebooks = 2;
    
    
    printf("%c%c needs %d pencils, %d notebooks, and 1 lunchbox\n", firstInitial, middleInitial, number_of_pencils, number_of_notebooks);
    printf("The total cost is $%.2f\n", number_of_pencils*pencils + number_of_notebooks*notebooks + lunchbox);
    
    
    return 0;
    
    
    }
    Code:
    Then here is the error message:  error: expected identifier or '(' before '{' token 
    
    & second error:  missing terminating " character

    I'm not sure what the errors are even if they are "included" can't see them. Copied the code exactly from the book and the errors are there. And I had difficulty getting this thread made because of the whole "" thing!

  2. #2
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    Also look at the printf() statement for the 2nd child and find the extraneous " in the data.

  3. #3
    Registered User rstanley's Avatar
    Join Date
    Jun 2014
    Location
    New York, NY
    Posts
    1,110
    You placed a '{' char before main() not after.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error message while running the code!
    By asylumcyclop in forum C Programming
    Replies: 1
    Last Post: 05-28-2018, 06:40 PM
  2. Problem with writing in CodeBlocks 13 12
    By giorgos giorgos in forum C Programming
    Replies: 2
    Last Post: 05-31-2015, 11:43 AM
  3. Why do I get this error message when compiling this code?
    By Videogamer555 in forum C Programming
    Replies: 5
    Last Post: 09-28-2014, 03:35 AM
  4. no error of compilation but my code makes codeblocks bug
    By funnydarkvador in forum C++ Programming
    Replies: 3
    Last Post: 03-19-2013, 12:31 AM
  5. error message code
    By Flex in forum C Programming
    Replies: 1
    Last Post: 02-27-2002, 12:21 PM

Tags for this Thread