NO

Author Topic: Need help again  (Read 3743 times)

Jitesh

  • Guest
Need help again
« on: October 20, 2004, 04:20:44 AM »
Hi it's me again I observed the code that you posted before and made the some improvements but it's still not working.

It seems that the part of my code that involves the tank and date info like there functions and structures is not being read. I beg u can some one have a look abd help me.

The infomration needs to be stored in a array, this array should preferably be decalred in another function could someone have a look please im beggin u guys i need help badly.



#include<stdio.h>

typedef struct {
   char make[10], model[10];
   int odometer;
} car_t;
typedef struct{
  int day, month, year;
}date_t;
typedef struct{
  double capacity, currentLevel;
}tank_t;



int getCar(car_t *c);
void showCar(car_t c);
int getDate( date_t *d);
void showDate(date_t d);
double getTank( tank_t *t);
void showTank(tank_t t);



int main(void)
{
   car_t c;
   date_t d;
   tank_t t;
   if (getCar(&c) != 0)
       return 0;

   showCar(c);
    return 0;

if (getDate(&d) != 0)
       return 0;

   showDate(d);

   return 0;

if (getTank(&t) != 0)
       return 0;

   showTank(t);

   return 0;

}

int getCar(car_t *c)
{
   printf("Enter the name of the car.\n");
   if (scanf("%s", c->make) != 1)
       return -1;

   printf("Enter the model of the car.\n");
   if (scanf("%s", c->model) != 1)
       return -1;

   printf("Enter the odometer reading of the car.\n");
   if (scanf("%d", &c->odometer) != 1)
       return -1;

   return 0;
}

void showCar(car_t c)
{
   printf("\n");
   printf("Name of the car is %s\n", c.make);
   printf("Model of the car is %s\n", c.model);
   printf("Odometer reading of the car is %d\n", c.odometer);
}


int getDate(date_t *d)
{
   printf("Enter the day of when the  car was made.\n");
   if (scanf("%s", &d->day) != 1)
       return -1;

   printf("Enter the month of when the car was made .\n");
   if (scanf("%s", &d->month) != 1)
       return -1;

   printf("Enter the year of when the car was made.\n");
   if (scanf("%d", &d->year) != 1)
       return -1;

   return 0;
}

void showDate(date_t d)
{
   printf("\n");
   printf("The day the car was made %d\n", d.day);
   printf("Month the car was made %d\n", d.month);
   printf("The year the car was made %d\n", d.year);

}

double getTank(tank_t *t)
{
   printf("Enter tank capcaity of the car.\n");
   if (scanf("%s", &t->capacity) != 1)
       return -1;

   printf("Enter the current level of the tank.\n");
   if (scanf("%s", &t->currentLevel) != 1)
       return -1;


   return 0;
}

void showTank(tank_t t)
{
   printf("\n");
   printf("The capacity of the tank is %lf\n", t.capacity);
   printf("The current level is %s\n", t.currentLevel);

}

CLR

  • Guest
Re: Need help again
« Reply #1 on: October 21, 2004, 02:18:47 AM »
Quote from: "Jitesh"


<..>

It seems that the part of my code that involves the tank and date info like there functions and structures is not being read...

<..>




Hi. Take a look at this code in your main() function.

-------------------------------------------------------
   car_t c;
   date_t d;
   tank_t t;
   if (getCar(&c) != 0)
      return 0;
   
   showCar(c);
    return 0;

    if (getDate(&d) != 0)  

-------------------------------------------------------

Offline jack

  • Member
  • *
  • Posts: 66
Need help again
« Reply #2 on: October 21, 2004, 03:15:46 AM »
tip: to post sourcecode use the tag [ code] your source code [ /code]
without the space, space inserted only so that the tag be visible and non working
 ▼
[ code]
#include<stdio.h>

typedef struct {
char make[10], model[10];
int odometer;
} car_t;
typedef struct{
int day, month, year;
}date_t;
typedef struct{
double capacity, currentLevel;
}tank_t;
[ /code]
 ▲ without the space