Please write it in c# program please and if possible no arrays only loops
Loop Introduction Assignment
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 1 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.
CODE:
/******************************************************************************
Online C# Compiler.
Code, Compile, Run and Debug C# program online.
Write your code in this editor and press "Run" button to execute
it.
*******************************************************************************/
using System;
class HelloWorld {
// using for loop
static void BMIFor() {
double bmi,height, weight;
// looping using for
for(int i=1; i<=3; i++) {
// get input from user
Console.Write("Enter weight in pounds: ");
weight = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter height in inches: ");
height = Convert.ToDouble(Console.ReadLine());
// calculate bmi
bmi = (weight * 703) / (height * height);
// display bmi
Console.WriteLine("BMI : {0:0.00}", bmi);
}
}
// using do while loop
static void BMIDoWhile() {
double bmi,height, weight;
int i = 1;
// looping using do
do {
// getting input
Console.Write("Enter weight in pounds: ");
weight = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter height in inches: ");
height = Convert.ToDouble(Console.ReadLine());
// calculate bmi
bmi = (weight * 703) / (height * height);
Console.WriteLine("BMI : {0:0.00}", bmi);
} while(i++!=3);
}
// using while loop
static void BMIWhile() {
double bmi,height, weight;
char choice;
// creating an infinite loop
while(true) {
// getting input from user
Console.Write("Enter weight in pounds: ");
weight = Convert.ToDouble(Console.ReadLine());
Console.Write("Enter height in inches: ");
height = Convert.ToDouble(Console.ReadLine());
// calculate bmi
bmi = (weight * 703) / (height * height);
Console.WriteLine("BMI : {0:0.00}", bmi);
// ask if user wants to continue
Console.WriteLine("Do you want to continue? (Y/N) : ");
choice = Console.ReadLine().ToLower()[0];
if(choice == 'n')
break;
}
}
// main
static void Main() {
// call all functions
Console.WriteLine("Calling first function.");
BMIFor();
Console.WriteLine("Calling second function.");
BMIDoWhile();
Console.WriteLine("Calling third function.");
BMIWhile();
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.