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

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 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.
C++ Please For this assignment, you will write a program that lets the user play against...
C++ Please For this assignment, you will write a program that lets the user play against the computer in a variation of the popular blackjack car game. In this variation of the game, two-six sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computer's hidden total without going over 21. Here are some suggestions for the game's design: Each round of the game is performed as an iteration of a loop...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector...
For this assignment, you need to write a parallel program in C++ using OpenMP for vector addition. Assume A, B, C are three vectors of equal length. The program will add the corresponding elements of vectors A and B and will store the sum in the corresponding elements in vector C (in other words C[i] = A[i] + B[i]). Every thread should execute an approximately equal number of loop iterations. The only OpenMP directive you are allowed to use is:...
Using C++ Write One one single program with two or more functioncallsWrite a C++...
Using C++ Write One one single program with two or more function callsWrite a C++ function, smallest Index, that takes as parameters an int array and its size and returns the index of the smallest element in the array. Also the program should test the function.Write another function that prompts the user to input a string and outputs the string in uppercase letters. You must use a character array to store the string.
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a...
introduction: C PROGRAMMING For this assignment you will write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT