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("%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