Dec 27, 2017 at 2:27pm UTC
Our professor gave us an example and we have to found the misstakes in this
program.
I can not find any misstakes.
Is somebody able to help me?
[code]
#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;
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;
if(car.abs)
price += 5000;
switch(car.brand)
{
case VOLVO:
break;
case BMW:
price *= 2;
break;
case FERRARI:
preice *=20;
break;
}
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;
}
[/FERRcode]
Last edited on Dec 27, 2017 at 2:31pm UTC
Dec 27, 2017 at 2:59pm UTC
Have you even tried to compile this program?
Your compiler should be able to help you locate most of the problems.
Dec 27, 2017 at 3:08pm UTC
goodness.
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 Dec 27, 2017 at 3:09pm UTC
Jan 5, 2018 at 7:58pm UTC
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 Feb 24, 2018 at 7:03pm UTC
Jan 19, 2018 at 2:04pm UTC
in your for loop there is missing a (+)