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...
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...
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 complete in only C++, using loops Assignment: For this assignment you’ll be designing a program...
Please complete in only C++, using loops Assignment: For this assignment you’ll be designing a program which can take the input of a decimal number and a numerical base, and convert the decimal number to that base. For example, if given the decimal number seven and the base two, your program should output it as 111, which is how seven is represented in binary. Another example, 8,943 in base 10, is 13,236 in base 9. You’ll need to perform these...
Using loop statements, write a C++ program which takes the number of items that a shopper...
Using loop statements, write a C++ program which takes the number of items that a shopper wants to buy, and then takes the price of each item, and at the end tells the shopper how much she must pay. This is a sample of the output: How many items do you have in your basket? 3 Enter the price in dollar? 10.25 Enter the price in dollar? 20.75 Enter the price in dollar? 67.5 You must pay 98.5 $ today.
You are to write a program in C to do the following in a loop for...
You are to write a program in C to do the following in a loop for the KL46Z . Prompt the user for a positive integer greater than 1 and sanity-check the input. If the number is a prime number, it is to be printed on a new line in red text. If the number is evenly divisible by 7, it is to be printed on a new line in green text. If the current number is evenly divisible by...
using C program Assignment Write a computer program that converts a time provided in hours, minutes,...
using C program Assignment Write a computer program that converts a time provided in hours, minutes, and seconds to seconds Functional requirements Input MUST be specified in hours, minutes, and seconds MUST produce the same output as listed below in the sample run MUST correctly compute times Nonfunctional requirements MUST adhere to program template include below MUST compile without warnings and errors MUST follow the code template provided in this assignment MUST NOT change " int main() " function MUST...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT