Programming Technique-1

Assignment 2

Text

#include <iostream>
using namespace std;
float getDV(float, float);
string getStatus(float);

int main()
{
float DV_percentage, nut_amount, rec_value;
string level;
char cont;

do
{
cout << "Please enter amounts of nutrients in one serving: ";
cin >> nut_amount;

cout << "Please enter amounts of nutrients recommended per day for individuals 4 years of age and older: ";
cin >> rec_value;

DV_percentage = getDV(nut_amount, rec_value);
level = getStatus(DV_percentage);

cout << "The amount of this nutrient is " << level << " in this product" << endl << endl;

cout << "Continue or Exit (Continue = Y, Exit = Other Alphabet): ";
cin >> cont;
cout << endl;

}
while (cont == 'Y' || cont == 'y');

return 0;
}

float getDV(float amount, float recommended)
{
return (amount / recommended * 100);
}

string getStatus(float DV)
{
if (DV <= 5)
{
return "low";
}
else if (DV >= 20)
{
return "high";
}
else
{
return "moderate";
}
}