0
jharvard@appliance (~/Dropbox/pset1): make greedy
clang -ggdb3 -O0 -std=c99 -Wall -Werror    greedy.c  -lcs50 -lm -o greedy
greedy.c:13:4: error: expected identifier or '('
   { 
   ^
1 error generated.
make: *** [greedy] Error 1

Here is the code it refers to:

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

int main (void);

int money;
int quater;
int dime; 
int nickle;
int penny;

{ 
do 
{
    printf("Please give me the amount of change owed.\n")
    int money = Getfloat ();
}
while 
     money > 0.00;

When I remove the curley braces it tells me the do and the while are incorrect. I have cross referenced it with other project and I have it set up the same way and that program is perfect in check50.

I am getting some failed checks when the vm boots up and I am not sure if this has something to do with this or not. I have tried shutting it down and rebooting several times.

1 Answer 1

2

You have a series of issues here, all to do with correct program structure. Some of them are hiding others.

First, int main (void); has a semicolon. This is causing problems and masking others. main should be structured like this:

// includes go here
#include....

// followed by main
int main(void)
{
    //main's code goes here, including variable definitions
}

Next, do/while is structured like this:

do
{
    // code goes here
} 
while ( test condition );

That should get you started. You would benefit from reviewing the material on program syntax, curly braces, and while loops.

If this answers your question, please accept this answer to remove the question from the unanswered question pool. Let's keep up on forum maintenance. ;-)

4
  • Yeah I know what your are talking about I have removed it and it tells me it belongs there. Commented Jul 25, 2015 at 11:31
  • jharvard@appliance (~/Dropbox/pset1): make greedy clang -ggdb3 -O0 -std=c99 -Wall -Werror greedy.c -lcs50 -lm -o greedy greedy.c:5:16: error: expected ';' after top level declarator int main (void) ^ ; greedy.c:13:4: error: expected identifier or '(' { ^ 2 errors generated. make: *** [greedy] Error 1 jharvard@appliance (~/Dropbox/pset1): Commented Jul 25, 2015 at 11:32
  • It tells you that the semicolon belongs there because compilers are not very smart. You have mismatched and unmatched curly braces and the compiler doesn't know how to fix them all. It only knows that a simple fix to the first problem is to "put a semicolon at the end of the prototype" except that it isn't a prototype of a function. This is also a case of a small problem masking a larger number of bigger problems that all have to be fixed. Compiler errors are usually helpful, but sometimes, they can be misleading and not point out the true problems. This is a well known case of that.
    – Cliff B
    Commented Jul 25, 2015 at 18:15
  • I am sorry I have tried adding and removing curly braces and no luck. Is there something for me to watch that will go into detail because I can not find anything online about this issue. Commented Jul 27, 2015 at 12:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .