This is a discussion on Structure Programming ---- Please Help within the C Programming forums, part of the General Programming Boards category; Define the structure yardsfeetinches with three simple variables int yards, int feet and float inches to declare distances in yards, ...

Define the structure yardsfeetinches with three simple variables int yards, int feet and float inches to declare distances in yards, feet and inches.

Write a program that adds two yardsfeetinches distances and store the result in third yardsfeetinches distance. Remember to make necessary inch to feet and feet to yard conversions. Note: 12 inches = 1 foot and 3 feet = 1 yard.

a.out
This program continues the introduction to structures.

Please enter yard, feet and inches: 1 2 3
1 yd 2 ft 3.00 + 2 yd 2 ft 9.75=4yd 2ft 0.75

Declare a second structure area which has two structure variables yardsfeetinches length and yardsfeetinches width. Write a program to calculate the area of a rectangle using the type area.

This is where I am at:

Code:
```#include <stdio.h>

typedef struct{
int yards;
int feet;
float inches;
}yardsfeetinches;

int main(void){
yardsfeetinches y;
yardsfeetinches y1;
yardsfeetinches y2;
float total;

y1.yards = 2;
y1.feet = 2;
y1.inches = 9.75;

printf("\nThis program continues the introduction to structures.");

printf("\n\nPlease enter yards, feet, and inches: ");
scanf("&#37;d%d%f", &y2.yards, &y2.feet, &y2.inches);

y.yards = y1.yards + y2.yards;
y.feet = y1.feet + y2.feet;
y.inches = y1.inches + y2.inches;

total = y.yards + y.feet * 0.33 + y.inches * 0.03;

y.yards = total/1.17;
y.feet = total/2.35;
y.inches = total/6.27;

printf("\n%d yd %d ft %f + 2 yd 2 ft 9.75 = ", y2.yards, y2.feet, y2.inches);
printf("%d yd %d ft %f\n", y.yards, y.feet, y.inches);

}```

Really could use some help on this

2. total probably should contain total number of yards, so why do you need the /1.17 part?

After you have stored some yards to y.yards - you probably want to decrease the total before calculating feet

As a side note - you should indent your code properly, and check the return value of scanf - you cannot be sure that the user enters values correcly, so without checking - you can start work on garbage

3. It would be great if you could state what is wrong rather than a generic "here is my code, help".

What is the program output? Does it compile? Do you get any errors? How do you know it is not working?

4. I would calculate your total in total inches and as vart said you need to modify total after you calculate the number of yards. I'm not sure what your weird divisors are for (1.17, 2.35, 6.27).

Code:
```total = y.yards * 36 + y.feet * 12 + y.inches;

y.yards = total / 36;
total -= y.yards * 36;

y.feet = total / 12;
total -= y.feet * 12;

y.inches = total;```