I'm having trouble rounding the numbers i'm getting in my output
here's my code:
#include<stdio.h>
int main() {
char gender;
float a1, a2, a3, a4, a5;
float waistmeasurement, wristmeasurement, hipmeasurement, forarmmeasurement;
float B, bodyweight, Bodyfat, Bodyfatpercentage;
printf("This program determines the body fat of a person.Enter your gender (f|F|m|M): ");
scanf("%c", &gender);
printf("\n");
if(gender=='F' || gender=='f'){
printf("Enter body weight (in pounds): \n");
scanf("%f", &bodyweight);
printf("Enter wrist measurement at fullest point (in inches): \n");
scanf("%f", &wristmeasurement);
printf("Enter waist measurement at navel (in inches): \n");
scanf("%f", &waistmeasurement);
printf("Enter hip measurement at fullest point (in inches): \n");
scanf("%f", &hipmeasurement);
printf("Enter forearm measurement at fullest point (in inches): \n");
scanf("%f", &forarmmeasurement);
a1=(bodyweight * 0.732) + 8.987;
a2=(wristmeasurement/3.140);
a3=(waistmeasurement * 0.157);
a4=(hipmeasurement * 0.249);
a5=(forarmmeasurement * 0.434);
B=(a1+a2-a3-a4+a5);
Bodyfat = bodyweight - B;
Bodyfatpercentage=(Bodyfat*100)/bodyweight;
printf("Body fat: %.7lf\n", Bodyfat);
printf("Body fat percentage: %.7lf\n", Bodyfatpercentage);
}
else if(gender=='M' || gender=='m'){
printf("Enter body weight (in pounds): \n");
scanf("%f", &bodyweight);
printf("Enter waist measurement at fullest point (in inches): \n");
scanf("%f", &waistmeasurement);
a1=(bodyweight * 1.082) + 94.42;
a2=waistmeasurement * 4.15;
B=a1-a2;
Bodyfat = bodyweight - B;
Bodyfatpercentage=(Bodyfat*100)/bodyweight;
printf("Body fat: %.7lf\n", Bodyfat);
printf("Body fat percentage: %.7lf\n", Bodyfatpercentage);
}
else{
printf("Invalid gender code.");
return(0);
}
return(0);
}
Here are the outputs i'm trying to get:
This program determines the body fat of a person.Enter your gender (f|F|m|M): m
Enter body weight (in pounds):
200
Enter waist measurement at fullest point (in inches):
32
Body fat: 21.980000
Body fat percentage: 10.990000
Here's the output i'm trying to get for female:
This program determines the body fat of a person.Enter your gender (f|F|m|M): f
Enter body weight (in pounds):
110
Enter wrist measurement at fullest point (in inches):
32
Enter waist measurement at navel (in inches):
30
Enter hip measurement at fullest point (in inches):
36
Enter forearm measurement at fullest point (in inches):
20
Body fat: 15.295917
Body fat percentage: 13.905379
If you have any doubts, please give me comment...
#include <stdio.h>
#include <math.h>
int main()
{
char gender;
float a1, a2, a3, a4, a5;
float waistmeasurement, wristmeasurement, hipmeasurement, forarmmeasurement;
float B, bodyweight, Bodyfat, Bodyfatpercentage;
printf("This program determines the body fat of a person.Enter your gender (f|F|m|M): ");
scanf("%c", &gender);
printf(" ");
if (gender == 'F' || gender == 'f')
{
printf("Enter body weight (in pounds): ");
scanf("%f", &bodyweight);
printf("Enter wrist measurement at fullest point (in inches): ");
scanf("%f", &wristmeasurement);
printf("Enter waist measurement at navel (in inches): ");
scanf("%f", &waistmeasurement);
printf("Enter hip measurement at fullest point (in inches): ");
scanf("%f", &hipmeasurement);
printf("Enter forearm measurement at fullest point (in inches): ");
scanf("%f", &forarmmeasurement);
a1 = (bodyweight * 0.732) + 8.987;
a2 = (wristmeasurement / 3.140);
a3 = (waistmeasurement * 0.157);
a4 = (hipmeasurement * 0.249);
a5 = (forarmmeasurement * 0.434);
B = (a1 + a2 - a3 - a4 + a5);
Bodyfat = (bodyweight - B);
Bodyfatpercentage = (Bodyfat * 100) / bodyweight;
printf("Body fat: %f ", Bodyfat);
printf("Body fat percentage: %f ", Bodyfatpercentage);
}
else if (gender == 'M' || gender == 'm')
{
printf("Enter body weight (in pounds): ");
scanf("%f", &bodyweight);
printf("Enter waist measurement at fullest point (in inches): ");
scanf("%f", &waistmeasurement);
a1 = (bodyweight * 1.082) + 94.42;
a2 = waistmeasurement * 4.15;
B = a1 - a2;
Bodyfat = ceilf((bodyweight - B)*100)/100;
Bodyfatpercentage=(Bodyfat*100)/bodyweight;
printf("Body fat: %f ", Bodyfat);
printf("Body fat percentage: %f ", Bodyfatpercentage);
}
else
printf("Invalid gender code.");
return (0);
}
I'm having trouble rounding the numbers i'm getting in my output here's my code: #include<stdio.h> int...
USING JAVA Write a program for calculating body fat and body fat percentage. The following simple formulas will be used for our calculations Body fat formula for female: A1 = (weight * .732) + 8.987 A2 = wrist measurement / 3.14 A3 = waist measurement * .157 A4 = hip measurement * .249 A5 = forearm measurement * .434 B = A1 + A2 - A3 – A4 + A5 Body fat = weight – B Body fat percentage =...
Whats wrong with my code? Please help! #include <stdio.h> int main() { //variables int m1, m2, m3; int a1, a2, a3; int f1, f2, f3; //input acceleration printf("Enter value for a1: "); printf("Enter value for a2: "); printf("Enter value for a3: "); scanf("%d %d %d",&a1,&a2,&a3); //input mass printf("Enter value for m1: "); printf("Enter value for m2: "); printf("Enter value for m3: "); scanf("%d %d %d",&m1,&m2,&m3); //functions f1=m1*a1; m1=f1/a1; a1=f1/m1; f2=m2*a2; m2=f2/a2; a2=f2/m2; f3=m3*a3; m3=f3/a3; a3=f3/m3; //command: printf("f1=%d\n, m1=%d\n, a1=%d\n"); printf("f2=%d\n,...
I'm having with my C program whenever i insert numbers it keeps outputting zeros here's the code: #include<stdio.h> int main(void) { int weeklyhours; double hourlyrate; double grosspay; double netpay; double federal; double state; double FICA; double Medicare; grosspay= weeklyhours * hourlyrate; federal = grosspay * 0.1; state = grosspay * 0.06; FICA = grosspay * 0.062; Medicare = grosspay * 0.0145; netpay = grosspay - (federal...
I'm having trouble getting a certain output with my program Here's my output: Please input a value in Roman numeral or EXIT or quit: MM MM = 2000 Please input a value in Roman numeral or EXIT or quit: mxvi Illegal Characters. Please input a value in Roman numeral or EXIT or quit: MXVI MXVI = 969 Please input a value in Roman numeral or EXIT or quit: EXIT Illegal Characters. Here's my desired output: Please input a value in...
i need help converting this code to java please #include<stdio.h> typedef struct{ int pid,at,bt,ct,tat,wt,f; }process; int main() { int n,i,j,st=0,c,tot=0,pno=0,swi=0; float atat=0,awt=0; printf("enter no of processes : "); scanf("%d",&n); process a[n],temp; for (i=0;i<n;i++){ a[i].pid=i+1; a[i].f=0; printf("enter at : "); scanf("%d",&a[i].at); printf("enter the bt : "); scanf("%d",&a[i].bt); printf("--------------------------- "); } while(1){ int min=999,c=n; if (tot==n) break; for (i=0;i<n;i++){ if ((a[i].at<=st)&&(a[i].f==0)&&(a[i].at<min)){ min=a[i].at; c=i; } } if(pno!=a[c].pid) swi++; if (c==n) st++; else{ a[c].ct=st+a[c].bt; st=st+a[c].bt; a[c].tat=a[c].ct-a[c].at; atat=atat+a[c].tat; a[c].wt=a[c].tat-a[c].bt; awt=awt+a[c].wt; a[c].f=1; tot++; } } printf("...
Having trouble with the do while/while loop and the switch statement. I got some of the switch statement but cant get the program to repeat itself like it should.What i have so far for my code is below. Any help is appreciated... i am not sure what I am doing wrong or what i am missing. I am completely lost on the while loop and where and how to use it in this scenario. import java.util.Scanner; public class sampleforchegg {...
i'm trouble getting my program to print this output and repeat until asked to quit the program Enter a telephone number using letterss (EXIT to quit): GET LOAN The corresponding telephone number is: 438-5626 Here's my code: #include <stdio.h> #include <string.h> char getNumber(char aC) { char c = ' '; switch (aC) { case 'A': case 'B': case 'C': c = '2'; break; case 'D': case 'E': case 'F': c = '3'; break; case 'G': case 'H': case 'I': c...