Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

If / else If Statements.

$
0
0
// First someone explain me if I can use an If loop within an If loop. This is what I did in this program. If No then can someone explain me how this program works.


#include <iostream>

using namespace std;

int main ()

{

	int Weight = 0;
	char Gender = 0;
	char ActivityLevel = 0;
	int Calories = 0;
	int NumberOfCalories = 0;


	cout << "Enter the Gender (M/F) : ";
		cin >> Gender;

	if (Gender == 'M' )
	{
	
		cout << "Enter the Activity Level (A/I) : ";
		     cin >> ActivityLevel;

	       if (ActivityLevel == 'A')
		{
		 cout << "Enter the Weight of the Person (In Pounds)  : ";
		    cin >> Weight;

			NumberOfCalories = (Weight * 15);
				cout << "The Total no. of Calories required are : " << NumberOfCalories << endl << endl;

		else 
			
			if (ActivityLevel == 'I')
		{
		
			cout << "Enter the Weight of the Person (In Pounds)  : ";
		    cin >> Weight;

			NumberOfCalories = (Weight * 13);
				cout << "The Total no. of Calories required are : " << NumberOfCalories << endl << endl;
		}

	else 
		
		if (Gender == 'F' )
	{
	
		cout << "Enter the Activity Level (A/I) : ";
		     cin >> ActivityLevel;

		if (ActivityLevel == 'A')
		{
		 cout << "Enter the Weight of the Person (In Pounds)  : ";
		    cin >> Weight;

			NumberOfCalories = (Weight * 12);
				cout << "The Total no. of Calories required are : " << NumberOfCalories << endl << endl;

		else  
			
			if (ActivityLevel == 'I')
		{
		
			cout << "Enter the Weight of the Person (In Pounds)  : ";
		    cin >> Weight;

			NumberOfCalories = (Weight * 10);
				cout << "The Total no. of Calories required are : " << NumberOfCalories << endl << endl;

	}
		}
	}

	return 0;

}

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>