Skip to content

Instantly share code, notes, and snippets.

@ErnyTech
Created January 25, 2018 19:20
Show Gist options
  • Save ErnyTech/e06da06252fc27cd29282a4cd2e730d1 to your computer and use it in GitHub Desktop.
Save ErnyTech/e06da06252fc27cd29282a4cd2e730d1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <cmath>
using std::cout;
using std::cin;
using std::string;
string peso (double a, double b) // a peso; b altezza
{
double f;
b = b / 100; // l'altezza in genere viene fornita in cm, quindi la converto in metri
f = a / pow(b, 2);
if (f < 16) {
return "Grave magrezza";
}
if (f >= 16 && f <= 16.99) {
return "Visibilmente sottopeso";
}
if (f > 17 && f <= 18.49) {
return "Leggermente sottopeso";
}
if (f >= 18.50 && f <= 24.99) {
return "Peso ideale";
}
if (f >= 25 && f <= 29.99 ) {
return "Sovrappeso";
}
if (f >= 30 && f <= 34.99) {
return "Obesità di I classe";
}
if (f >= 35 && f <= 40) {
return "Obesità di II classe";
}
if (f > 40) {
return "Obesità di III classe";
}
}
int main() {
double a,b;
cout << "Inserisci l'altezza: ";
cin >> b;
cout << "Inserisci il peso: ";
cin >> a;
cout << "\n" + peso(a, b) + "\n";
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment