NO

Author Topic: Writing new program for class, I get mulitple errors. Could someone look & help  (Read 5700 times)

DEPDOGC632

  • Guest
I have typed out a new program for class and I am unable to understand what it is that is wrong with this. if someone could give me some pointers on getting this to work, I would appreciate it very much. I get multiple error codes!!! LOL

/*
  * Determines the value of a collection of coins.
  */
#include <stdio.h>
int
main(void)
{
   char first, middle, last;/ * input - 3 initials                      */
   int pennies, nickles;    /* input - count of each coin type   */
   int dimes, quarters;    /* input - count of each coin type   */
   int dollars;                /* input - count of each coin type   */
   int change;               /* ouput - change amount              */
   int total_dollars;       /* output - dollar amount               */
   int total_cents;         /* total cents                               */

   /* Get and display the customer's initials. */
   printf ("Type in 3 initials and press return> ");
   scanf("%c%c%c", &first, &middle, &last);
   printf("\n%c%c%c,  please enter your coin information.\n",
                  first, middle, last);

   /* get the count of each kind of coin. */
   printf("Number of $ coins > ");
   scanf("%d", &dollars);
   printf("Number of quarters> ");
   scanf("%d", &quarters);
   printf("Number of dimes    > ");
   scanf("%d", &dimes);
   printf("Number of nickles  > ");
   scanf("%d", &nickles);
   printf("Number of pennies >");
   scanf("%d", &pennies);

       /* Compute the total value in cents. */
   total_cents = 100 * dollars +25 * quarters + 10 * dimes +
   5 * nickles + pennies;

       /* Find the value in dollars and change. */
   dollars = total_cents / 100;
   change = total_cents % 100;

   /* Display the credit slip with value in dollars and change. */
   printf("\n\n%c%c%c Coin Credit\nDollars: %d\nChange: %d cents\n",
      first, middle, last, dollars, change);

   return (0);
}
« Last Edit: June 23, 2011, 11:26:49 PM by DEPDOGC632 »

czerny

  • Guest
A comment is starting with /* not / *!



czerny

CommonTater

  • Guest
I have typed out a new program for class and I am unable to understand what it is that is wrong with this. if someone could give me some pointers on getting this to work, I would appreciate it very much. I get multiple error codes!!! LOL

It would help rather a lot if we knew what those error codes are... 
When Pelles C reports errors in source code there is always a line number in the error report.  If you click on it in the output pane it should take you directly to the offending line... from there you read the error message and correct the error...

Here's what I got when I compiled it...
Code: [Select]
Building main.obj.
E:\C_Code\Experiments\testprog\main.c(8): warning #2114: Local 'last' is not referenced.
E:\C_Code\Experiments\testprog\main.c(8): warning #2114: Local 'middle' is not referenced.
E:\C_Code\Experiments\testprog\main.c(8): warning #2114: Local 'first' is not referenced.
E:\C_Code\Experiments\testprog\main.c(8): error #2001: Syntax error: expected '}' but found '/'.
E:\C_Code\Experiments\testprog\main.c(6): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(8): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(8): error #2001: Syntax error: expected ';' but found '-'.
E:\C_Code\Experiments\testprog\main.c(8): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(8): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(8): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(8): error #2001: Syntax error: expected ';' but found '*'.
E:\C_Code\Experiments\testprog\main.c(8): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(8): error #2092: Missing identifier.
E:\C_Code\Experiments\testprog\main.c(8): error #2001: Syntax error: expected ';' but found '/'.
E:\C_Code\Experiments\testprog\main.c(17): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(17): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(17): error #2120: Redeclaration of 'printf', previously declared at E:\Programs\PellesC\Include\stdio.h(177); expected 'int __cdecl function(const char * restrict, ...)' but found 'int __cdecl function()'.
E:\C_Code\Experiments\testprog\main.c(18): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(18): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(18): error #2120: Redeclaration of 'scanf', previously declared at E:\Programs\PellesC\Include\stdio.h(178); expected 'int __cdecl function(const char * restrict, ...)' but found 'int __cdecl function()'.
E:\C_Code\Experiments\testprog\main.c(19): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(19): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(23): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(23): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(24): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(24): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(25): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(25): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(26): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(26): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(27): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(27): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(28): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(28): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(29): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(29): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(30): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(30): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(31): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(31): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(32): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(32): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(35): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(36): error #2069: Initializer must be constant.
E:\C_Code\Experiments\testprog\main.c(39): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(39): error #2069: Initializer must be constant.
E:\C_Code\Experiments\testprog\main.c(40): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(40): error #2069: Initializer must be constant.
E:\C_Code\Experiments\testprog\main.c(43): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(43): error #2001: Syntax error: expected ')' but found 'string constant'.
E:\C_Code\Experiments\testprog\main.c(46): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(46): warning #2099: Missing type specifier; assuming 'int'.
E:\C_Code\Experiments\testprog\main.c(46): error #2001: Syntax error: expected ')' but found 'integer constant'.
E:\C_Code\Experiments\testprog\main.c(46): error #2092: Missing identifier.
E:\C_Code\Experiments\testprog\main.c(46): error #2001: Syntax error: expected ';' but found 'integer constant'.
E:\C_Code\Experiments\testprog\main.c(46): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(46): error #2156: Unrecognized declaration.
E:\C_Code\Experiments\testprog\main.c(47): error #2156: Unrecognized declaration.
*** Error code: 1 ***
Done.

The error on line 8 is because your comment is improperly formed... /* ... no spaces.
Correcting that, left me with this...
Code: [Select]
Building main.obj.
E:\C_Code\Experiments\testprog\main.c(13): warning #2114: Local 'total_dollars' is not referenced.
Building testprog.exe.
Done.
and a program that compiled and ran...

Most errors are pretty obvious, spelling mistakes, capitalization, braces mismatched etc.  Some, like messed up comments can set off a cascade of errors, like yours did.


DEPDOGC632

  • Guest
Tater, thanks for looking at this for me. Sorry I didn't include the errors, but I had exactly what you did for the errors. Now with reference to line 8, I don't know what you mean by "no spaces"! No spaces where??? I tried taking all the spaces out and tried around just taking space out around the "/*", but I am still lost.

char first, middle, last; /* input - 3 initials                         */           
 
Where is the incorrect space you are referring too?

Thanks again!!


CommonTater

  • Guest
Tater, thanks for looking at this for me. Sorry I didn't include the errors, but I had exactly what you did for the errors. Now with reference to line 8, I don't know what you mean by "no spaces"! No spaces where??? I tried taking all the spaces out and tried around just taking space out around the "/*", but I am still lost.

char first, middle, last; /* input - 3 initials                         */           

Where is the incorrect space you are referring too?

In your code on line 8.

If you haven't...  you should set your Code editor to a fixed pitch font... Terminal, Fixedsys, Courier, etc. so that spaces are full width characters and columns line up vertically... it makes this kind of stuff a LOT easier to spot.

Look at the color highlighting of your comments... you will discover the comment on that line is the wrong color...  That is because the first comment marker /* has a space between the slash and the asterisk. 

Powers of observation are of keen importance in programming.  It's not "general grammar" or even "strict grammar"... With C, it's letter perfect grammar.  Even the slightest deviation from what it expects can cause very real problems; like the one you're experiencing.