C Programming *Notice: I can only edit the part where it says in /* Your solutio
ID: 3876233 • Letter: C
Question
C Programming
*Notice: I can only edit the part where it says in /* Your solution goes here */ the other part of the code i can't touch it please the solution should be inside that part ad using the code provided
Question 1
Complete the function ConvertToFeetAndInches to convert totalInches to feet and inches. Return feet and inches using the HeightFtIn struct. Ex: 14 inches is 2 feet and 2 inches.
#include <stdio.h>
typedef struct HeightFtIn_struct {
int feet;
int inches;
} HeightFtIn;
HeightFtIn ConvertToFeetAndInches(int totalInches) {
HeightFtIn tempVal;
/* Your solution goes here */
}
int main(void) {
HeightFtIn studentHeight;
int totalInches;
scanf("%d", &totalInches);
studentHeight = ConvertToFeetAndInches(totalInches);
printf("%d feet and %d inches ", studentHeight.feet, studentHeight.inches);
return 0;
}
Question2
Complete the function ConvertToWeeksAndDays to convert totalDays to weeks and days. Return weeks and days using the TimeWeekDay struct. Ex: 16 days is 2 weeks and 2 days.
#include <stdio.h>
typedef struct TimeWeekDay_struct {
int weeks;
int days;
} TimeWeekDay;
TimeWeekDay ConvertToWeeksAndDays(int totalDays) {
TimeWeekDay tempVal;
/* Your solution goes here */
}
int main(void) {
TimeWeekDay elapsedDays;
int totalDays;
scanf("%d", &totalDays);
elapsedDays = ConvertToWeeksAndDays(totalDays);
printf("%d weeks and %d days ", elapsedDays.weeks, elapsedDays.days);
return 0;
}
Explanation / Answer
#include <stdio.h>
typedef struct HeightFtIn_struct {
int feet;
int inches;
} HeightFtIn;
HeightFtIn ConvertToFeetAndInches(int totalInches) {
HeightFtIn tempVal;
// 1 feet = 12 inches
// Assigning quotient to feet and reminder to inches
tempVal.feet = totalInches / 12;
tempVal.inches = totalInches % 12;
return tempVal;
}
int main(void) {
HeightFtIn studentHeight;
int totalInches;
scanf("%d", &totalInches);
studentHeight = ConvertToFeetAndInches(totalInches);
printf("%d feet and %d inches ", studentHeight.feet, studentHeight.inches);
return 0;
}
/*SAMPLE OUTPUT
14
1 feet and 2 inches
*/
#include <stdio.h>
typedef struct TimeWeekDay_struct {
int weeks;
int days;
} TimeWeekDay;
TimeWeekDay ConvertToWeeksAndDays(int totalDays) {
TimeWeekDay tempVal;
// A week has 7 days
// Assigning quotient to weeks and reminder to days
tempVal.weeks = totalDays / 7;
tempVal.days = totalDays % 7;
return tempVal;
}
int main(void) {
TimeWeekDay elapsedDays;
int totalDays;
scanf("%d", &totalDays);
elapsedDays = ConvertToWeeksAndDays(totalDays);
printf("%d weeks and %d days ", elapsedDays.weeks, elapsedDays.days);
return 0;
}
/* SAMPLE OUTPUT
16
2 weeks and 2 days
*/
#include <stdio.h>
typedef struct HeightFtIn_struct {
int feet;
int inches;
} HeightFtIn;
HeightFtIn ConvertToFeetAndInches(int totalInches) {
HeightFtIn tempVal;
// 1 feet = 12 inches
// Assigning quotient to feet and reminder to inches
tempVal.feet = totalInches / 12;
tempVal.inches = totalInches % 12;
return tempVal;
}
int main(void) {
HeightFtIn studentHeight;
int totalInches;
scanf("%d", &totalInches);
studentHeight = ConvertToFeetAndInches(totalInches);
printf("%d feet and %d inches ", studentHeight.feet, studentHeight.inches);
return 0;
}
/*SAMPLE OUTPUT
14
1 feet and 2 inches
*/
#include <stdio.h>
typedef struct TimeWeekDay_struct {
int weeks;
int days;
} TimeWeekDay;
TimeWeekDay ConvertToWeeksAndDays(int totalDays) {
TimeWeekDay tempVal;
// A week has 7 days
// Assigning quotient to weeks and reminder to days
tempVal.weeks = totalDays / 7;
tempVal.days = totalDays % 7;
return tempVal;
}
int main(void) {
TimeWeekDay elapsedDays;
int totalDays;
scanf("%d", &totalDays);
elapsedDays = ConvertToWeeksAndDays(totalDays);
printf("%d weeks and %d days ", elapsedDays.weeks, elapsedDays.days);
return 0;
}
/* SAMPLE OUTPUT
16
2 weeks and 2 days
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.