Question

In: Computer Science

Loop Introduction Assignment Please write a program in c# Using the conditions below, write one program...

Loop Introduction Assignment

Please write a program in c#

Using the conditions below, write one program that calculates a person’s BMI. Your main() function will call functions 1, 2, and 3.

Your program will contain three functions:

Function #1:

Will ask the user for their weight in pounds and their height in inches.   Your function will convert the weight and height into Body Mass Index (BMI). The formula for converting weight into BMI is as follows:

BMI = Weight * 703 / Height2

Your function will do this using a for loop and must display the BMI for 3 people, one at a time. In other words, display the BMI for person

before asking for the next person’s information.

Function #2:

This function will do the exact same thing as function #1, except you will use a do-while loop.                        

Function #3:

Using a while loop, write the same steps as function #1, but as an indefinite loop where we continue to ask the user if they would like to calculate the BMI again. Continue to do so until the user replies with either an ‘N’ or an ‘n’

Reserve Point Opportunity!!

Complete the above program calling a fourth function that will calculate and return the BMI.  

Solutions

Expert Solution

The below program calculates BMI of a person after taking user's height and weight as input. It contains four functions, the first three functions (i.e. Function1, 2 and 3) uses for, do-while and infinite while loop to perform a same specific task (i.e. takes users input and provide BMI as output). And the last Function4 calculates the BMI after taking weight and height as argument from Function1, 2 and 3 and then finally returns the BMI to the respective functions.

Source Code -

using System.IO;
using System;

class BMI
{
static void Main()
{
double weight=0;   
double height=0;
Function1(weight,height);
Function2(weight,height);
Function3(weight,height);
}
  
static void Function1(double w, double h)
{
Console.WriteLine(" Inside Function 1 : ");
for(int i=1; i<4; ++i)
{
Console.WriteLine("For person "+ i +" :");
Console.WriteLine("Enter weight in pounds :");
w=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter height in inches :");
h=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("BMI :" + Function4(w,h));
Console.WriteLine();
}
}
  
static void Function2(double w, double h)
{
Console.WriteLine(" Inside Function 2 : ");
int i=1;
do
{
Console.WriteLine("For person "+ i +" :");
Console.WriteLine("Enter weight in pounds :");
w=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter height in inches :");
h=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("BMI :" + Function4(w,h));
Console.WriteLine();
++i;
}
while(i<4);
}
  
static void Function3(double w, double h)
{
Console.WriteLine(" Inside Function 3 : ");
int i=1;
while(true)
{
Console.WriteLine("For person "+ i +" :");
Console.WriteLine("Enter weight in pounds :");
w=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("Enter height in inches :");
h=Convert.ToDouble(Console.ReadLine());
Console.WriteLine("BMI :" + Function4(w,h));
Console.WriteLine();
++i;
Console.WriteLine("Enter n or N to exit or else press any other character to continue : ");
char[] ch=Console.ReadLine().ToCharArray();
if(ch[0]=='n' || ch[0]=='N')
{
break;
}
Console.WriteLine();
  
}
}
  
static double Function4(double w, double h)
{
double BMI=(w*703)/(h*h);
return BMI;
}
}


Related Solutions

For this assignment you will write a Java program using a loop that will play a...
For this assignment you will write a Java program using a loop that will play a simple Guess The Number game. Create a new project named GuessANumber and create a new Java class in that project named GuessANumber.java for this assignment. The program will randomly generate an integer between 1 and 200 (including both 1 and 200 as possible choices) and will enter a loop where it will prompt the user for a guess. If the user has guessed the...
Write a program using c++. Write a program that uses a loop to keep asking the...
Write a program using c++. Write a program that uses a loop to keep asking the user for a sentence, and for each sentence tells the user if it is a palindrome or not. The program should keep looping until the user types in END. After that, the program should display a count of how many sentences were typed in and how many palindromes were found. It should then quit. Your program must have (and use) at least four VALUE...
Multiples of 2 and 3: write a c++ program Using a while loop, write a program...
Multiples of 2 and 3: write a c++ program Using a while loop, write a program that reads 10 integer numbers. The program shall count how many of them are multiples of 2, how many are multiples of 3, and how many are NOT multiples of either 2 or 3. The output should be similar to the one shown below.
1 for each of the problems listed below write the c++ program while using WHILE loop...
1 for each of the problems listed below write the c++ program while using WHILE loop structures A program will display each term in the following sequence 1 -10 100 -1000 10000 -100000 1000000 A program will calculate and display the corresponding celsius temperatures for the given Farenheit ones from 0f to 212 f (hint c=(f-32/1.8)
Please if you are able to answer the question below: Write C++ program using native C++...
Please if you are able to answer the question below: Write C++ program using native C++ (you can use STL)  that produces Huffman code for a string of text entered by the user.  Must accept all ASCII characters.  Pleas explain how you got frequencies of characters, how you sorted them, how you got codes.
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to...
Introduction to Java Programing Using Loop Create a simple calculator program using loop Ask user to input two numbers using scanner class Print the instruction of the menu for the calculator program Ask user to press 0 to Quit Ask user to press 1 to Add Ask user to press 2 to Substract Ask user to press 3 to Multiply Ask user to press 4 to Divide Perform correct calcuation based on user inputs and print the result Print error...
Write a program that uses loops (both the for-loop and the while loop). This assignment also...
Write a program that uses loops (both the for-loop and the while loop). This assignment also uses a simple array as a collection data structure (give you some exposure to the concept of data structure and the knowledge of array in Java). In this assignment, you are asked to construct an application that will store and retrieve data. The sequence of data retrieval relative to the input is Last In First Out (LIFO). Obviously, the best data structure that can...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number...
CODE MUST BE IN C++ (please use for loop) write a program that loops a number from 1 to 10 thousand and keeps updating a count variable (count variable starts at 0 ) according to these rules: n1 = 14 n2 = 54 n3 = 123 if the number is divisible by n1, increase count by 1 if the number is divisible by n2, increase count by 2 if the number is divisible by n3, increase count by 3 if...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will...
Please code in C# - (C - Sharp) Assignment Description Write out a program that will ask the user for their name; the length and width of a rectangle; and the length of a square. The program will then output the input name; the area and perimeter of a rectangle with the dimensions they input; and the area and perimeter of a square with the length they input. Tasks The program needs to contain the following A comment header containing...
Please write a Java program using a for loop with a switch statement to enter 5...
Please write a Java program using a for loop with a switch statement to enter 5 quiz scores. Each should be out of ten points and give the corresponding grade A, B , C etc.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT