Skip to content

Commit

Permalink
added & modified
Browse files Browse the repository at this point in the history
  • Loading branch information
jesushilarioh committed Feb 10, 2019
1 parent 4992665 commit 58bc7e8
Show file tree
Hide file tree
Showing 25 changed files with 548 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,35 +20,32 @@
* calories or fat grams were incorrectly entered.
*
* Jesus Hilario Hernandez
* February 20, 2018
* February 10, 2019
*
********************************************************************/
#include <iostream>
using namespace std;
int main()
{
// Varibles
float cal_from_fat,
float calories_from_fat,
fat_grams,
per_of_cal,
total_cal;
percentage_of_calories,
total_calories;

// Ask for the number of calories & fat grams in food
cout << "\nEnter number of calories: ";
cin >> total_cal;
cin >> total_calories;

if (total_cal > 0)
if (total_calories > 0)
{
cout << "Enter number of fat grams: ";
cin >> fat_grams;

if (fat_grams > 0)
{
// Calculate
cal_from_fat = fat_grams * 9;
per_of_cal = (cal_from_fat / total_cal) * 100;

if (cal_from_fat > total_cal)
calories_from_fat = fat_grams * 9;
percentage_of_calories = (calories_from_fat / total_calories) * 100; // .45 == 45

if (calories_from_fat > total_calories)
{
cout << "\nCalories from fat cannot be greater\n";
cout << "then the total number of calories." << endl;
Expand All @@ -58,30 +55,25 @@ int main()
}
else
{
// Display the % of calories from fat
cout << "Total calories = " << total_cal << " cal"<< endl;
cout << "Total calories = " << total_calories << " cal"<< endl;
cout << "Total fat grams = " << fat_grams << " g" << endl;
cout << "Total calories from fat = " << cal_from_fat << " cal from fat"<< endl;
cout << "Total percentage of calories from fat = " << per_of_cal << '%' << endl;
cout << "Total calories from fat = " << calories_from_fat << " cal from fat"<< endl;
cout << "Total percentage of calories from fat = " << percentage_of_calories << '%' << endl;
cout << endl;
}
}
else
{
// Explain error and try again
cout << "We're sorry. Total fat grams must be more than 0.\n";
cout << "We're sorry. Fat grams must be more than 0.\n";
cout << "Please rerun the progarm and try again." << endl;
}
}
else
{
// Explain error and try again
cout << "We're sorry. Total calories must be more than 0.\n";
cout << "Please rerun the progarm and try again." << endl;
}


// If calories from fat are less than 30%, display "food is low in fat"

// Terminate program
return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
using namespace std;
int main()
{
// Variables
double wavelength;
// Ask for wavelength (in meters)
cout << "/nEnter wavelength (in meters): ";
cin >> wavelength;

// Display the type of wave according to chart
cout << "\nEnter wavelength (in meters): ";
cin >> wavelength; // .0001

if (wavelength >= 1E-2)
cout << "Radio Waves" << endl;
else if (wavelength <= 1E-2 && wavelength >= 1E-3)
Expand All @@ -39,8 +37,7 @@ int main()
else if (wavelength <= 1E-11)
cout << "Gamma Rays" << endl;

// Format line break
cout << endl;
// Terminate program

return 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,76 +23,80 @@
* distances less than 0.
*
* Jesus Hilario Hernandez
* February 21, 2018
* February 21, 2019
*
********************************************************************/
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Variables
int user_select;
const int AIR_FEET_PER_SECOND = 1100,
WATER_FEET_PER_SECOND = 4900,
STEEL_FEET_PER_SECOND = 16400,
MINIMUM_DISTANCE = 0;

int user_menu_choice;

float length_of_travel,
amount_of_time;

// Display menu
// Ask user to select from menu
cout << "===================" << endl;
cout << " Choose one: " << endl;
cout << "-------------------" << endl;
cout << " 1. Air " << endl;
cout << " 2. Water " << endl;
cout << " 3. Steel " << endl;
cout << "===================" << endl;
cin >> user_select;
cin >> user_menu_choice;

// Decision statement
switch (user_select)
switch (user_menu_choice)
{
case 1:
case 2:
case 3:
// Ask user to enter the distance sound wave will travel
cout << "\nHow far will the sound wave travel? ";
cin >> length_of_travel;

// If less that 0, error check
if (length_of_travel < 0)
if (length_of_travel < MINIMUM_DISTANCE)
{
cout << "\nWe're sorry. Distance must be more than 0.\n";
cout << "\nError. Distance must be more than 0.\n";
cout << "Rerun the program and try again.\n" << endl;
}
else
{
if (user_select == 1)
// Valid
if (user_menu_choice == 1)
{
amount_of_time = length_of_travel / 1100;
amount_of_time = length_of_travel /
AIR_FEET_PER_SECOND;
cout << "In air ";

}
else if (user_select == 2)
else if (user_menu_choice == 2)
{
amount_of_time = length_of_travel / 4900;
amount_of_time = length_of_travel /
WATER_FEET_PER_SECOND;
cout << "In water ";
}
else if (user_select == 3)
else if (user_menu_choice == 3)
{
amount_of_time = length_of_travel / 16400;
amount_of_time = length_of_travel /
STEEL_FEET_PER_SECOND;
cout << "In steel ";
}

// Display amount of time it will take
cout << setprecision(4) << fixed;
cout << "the sound wave will take " << amount_of_time;
cout << " seconds to travel." << endl << endl;
}
break;

default:
cout << "\nWe're sorry. Choose a number between 1 and 3." << endl;
cout << "Rerun the program and try again.\n" << endl;
break;
}

// Terminate program

return 0;
}
}
Loading

0 comments on commit 58bc7e8

Please sign in to comment.