C :: Aufgabe #280
1 Lösung
WHtR (Waist to Height Ratio) berechnen
Anfänger - C
von JKooP
- 10.05.2020 um 09:17 Uhr
Schreibe ein Programm zur Ermittlung des WHtR- Wertes aus Taillenumfang + Körpergröße und der daraus resultierenden Bewertung.
Es sollen sowohl das Geschlecht (m/w) als auch das Kindesalter bzw. der Altersfaktor für Erwachsene berücksichtigt werden.
Viel Spaß
Es sollen sowohl das Geschlecht (m/w) als auch das Kindesalter bzw. der Altersfaktor für Erwachsene berücksichtigt werden.
Viel Spaß
Lösungen:
#include <stdio.h>
#include <string.h>
#include <math.h>
#define ZUSCHLAG_ALTER_VON 40
#define ZUSCHLAG_ALTER_BIS 49
#define ZUSCHLAG_ALTER_WERT 0.01
enum Geschlecht { divers = 0, maennlich = 1, weiblich = 2 };
void main()
{
double umfang = 100;
double groesse = 185;
double alter = 45;
enum Geschlecht geschlecht = maennlich;
double index = umfang / groesse;
double korrektur_weiblich;
if (index < 0.34) korrektur_weiblich = 0;
else if (index >= 0.34 && index <= 0.45) korrektur_weiblich = 0.01;
else if (index >= 0.46 && index <= 0.51) korrektur_weiblich = 0.03;
else if (index >= 0.52 && index <= 0.63) korrektur_weiblich = 0.04;
else korrektur_weiblich = 0.05;
double alterszuschlag = (alter - ZUSCHLAG_ALTER_VON) * ZUSCHLAG_ALTER_WERT;
double korrektur_alter = alter >= ZUSCHLAG_ALTER_VON && alter <= ZUSCHLAG_ALTER_BIS ? alterszuschlag : 0;
double whtr_index = index - (geschlecht == weiblich ? korrektur_weiblich : 0) + korrektur_alter;
char whtr_kategorie[20];
if (alter < 15)
{
if (whtr_index < 0.34) strcpy(whtr_kategorie, "Untergewicht");
else if (whtr_index >= 0.34 && whtr_index <= 0.45) strcpy(whtr_kategorie, "Normalgewicht");
else if (whtr_index >= 0.46 && whtr_index <= 0.51) strcpy(whtr_kategorie, "Uebergewicht");
else if (whtr_index >= 0.52 && whtr_index <= 0.63) strcpy(whtr_kategorie, "Adipositas");
else strcpy(whtr_kategorie, "schwere Adipositas");
}
else if (alter >= 15 && alter <= 49)
{
if (whtr_index < 0.4) strcpy(whtr_kategorie, "Untergewicht");
else if (whtr_index >= 0.4 && whtr_index <= 0.5) strcpy(whtr_kategorie, "Normalgewicht");
else if (whtr_index >= 0.51 && whtr_index <= 0.56) strcpy(whtr_kategorie, "Uebergewicht");
else if (whtr_index >= 0.57 && whtr_index <= 0.68) strcpy(whtr_kategorie, "Adipositas");
else strcpy(whtr_kategorie, "schwere Adipositas");
}
else
{
if (whtr_index < 0.4) strcpy(whtr_kategorie, "Untergewicht");
else if (whtr_index >= 0.4 && whtr_index <= 0.6) strcpy(whtr_kategorie, "Normalgewicht");
else if (whtr_index >= 0.61 && whtr_index <= 0.66) strcpy(whtr_kategorie, "Uebergewicht");
else if (whtr_index >= 0.67 && whtr_index <= 0.78) strcpy(whtr_kategorie, "Adipositas");
else strcpy(whtr_kategorie, "schwere Adipositas");
}
printf("Index: %.2f\tKategorie: %s", floor(100 * whtr_index) / 100, whtr_kategorie);
}
