I have a question

Our professor gave us an example and we have to found the misstakes in this
I can not find any misstakes.
Is somebody able to help me?


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

typedef enum brandname{VOLVO, BMW, FERRARI}brandname_t;

typedef struct car{
brandname_t brand;
int vmax;
int abs;
unsigned char doors;

car_t new_car(brandname_t brand, int vmax, int abs, unsigned char doors)
car_t car;
car.brand = brand;
car.vmax = vmax;
car.abs = abs;
car.doors = doors;
return car;
int price(car_t car)
int price;
price = car.vmax*50;
price *= car.doors;
price += 5000;
case VOLVO:
case BMW:
price *= 2;
preice *=20;
return price;

int main()
car_t cars[3];
cars[0] = new_car(VOLVO,190,1,5);
cars[1] = new_car(BMW,210,1,4);
cars[2] = new_car(FERRARI,260,350,2);

int sum = 0;
int i;
for(i=0; i>3; i+)
int prize = price(cars[i]);
printf("price%d: %d\n",i,prize);
sum += prize;


printf("duration: %d\n",sum);

return 0;

Last edited on
Have you even tried to compile this program?

Your compiler should be able to help you locate most of the problems.


Is this supposed to be pure C not c++??

The enum looks wrong, or at least weird, why the typedef??
The struct typedef also looks wrong, but maybe it is ok for C.

Have you tried feeding it to a compiler and seeing what it chokes on?
Last edited on
Hello javaupdater,

When using code tags this may help.


As suggested compile the program and you can find two problems. One is a spelling mistake and the other deals with the for loop in main. Although the for loop has more than just a syntax problem which you can see when the program runs.

Hope that helps,

thank you
Also, a variable price is defined but not preice. In line 37, it says preice*=20 but preice isn't defined. And on line 52; it only says for(i=0; i<3; i+). that would compile an error
Last edited on
in your for loop there is missing a (+)
Topic archived. No new replies allowed.