Question

Please write it in c# program please and if possible no arrays only loops Loop Introduction...

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.  

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write a modular program that calculates and displays a person’s body mass index (BMI). The BMI...
Write a modular program that calculates and displays a person’s body mass index (BMI). The BMI is often used to determine whether a person is overweight or underweight for his or her height. A person’s BMI is calculated with the following formula BMI = weight * 703/height2 Where weight is measured in pounds and height is measured in inches. The program should ask the user to enter his or her weight and height and then display the user’s BMI. The...
In C programming language please. -Construct a program that will make use of user defined functions,...
In C programming language please. -Construct a program that will make use of user defined functions, the do/while loop, the for loop and selection. -Using a do/while loop, your program will ask/prompt the user to enter in a positive value representing the number of values they wish to have processed by the program or a value to quit/exit. -If the user enters in a 0 or negative number the program should exit with a message to the user indicating they...
Write a program which: Write a program which uses the following arrays: empID: An array of...
Write a program which: Write a program which uses the following arrays: empID: An array of 7 integers to hold employee identification numbers. The array should be initialized with the following values: 1, 2, 3, 4, 5, 6, 7. Hours: an array of seven integers to hold the number of hours worked by each employee. payRate: an array of seven doubles to hold each employee’s hourly pay rate. Wages: an array of seven doubles to hold each employee’s gross salary....
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an...
Arrays, loops, functions: Lotto Element Repeated Function Write a function that that takes as parameters an array of ints, an int value named element, and an int value named end. Return a bool based on whether the element appears in the array starting from index 0 and up to but not including the end index. Generate Random Array Write a function that takes as parameters an array of integers and another integer for the size of the array. Create a...
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask...
Write a program that utilizes a DO-WHILE loop to redisplay a menu to the user. Ask the user to input their favorite SuperHero and display a positive or funny comment about the chosen SuperHero. If RBG is chosen, display "You can't spell TRUTH without RUTH." Utilize a Do-While Loop to redisplay the menu to the user after item 1, 2 or 3 is executed. If item 4 is chosen, end the program. If the user chooses 4, end the program....
Assignment #4 – Student Ranking : In this assignment you are going to write a program...
Assignment #4 – Student Ranking : In this assignment you are going to write a program that ask user number of students in a class and their names. Number of students are limited to 100 maximum. Then, it will ask for 3 test scores of each student. The program will calculate the average of test scores for each student and display with their names. Then, it will sort the averages in descending order and display the sorted list with students’...
You will write a program that loops until the user selects 0 to exit. In the...
You will write a program that loops until the user selects 0 to exit. In the loop the user interactively selects a menu choice to compress or decompress a file. There are three menu options: Option 0: allows the user to exit the program. Option 1: allows the user to compress the specified input file and store the result in an output file. Option 2: allows the user to decompress the specified input file and store the result in an...
Python code only! (Do not include breaks or continue functions) Write a program that asks the...
Python code only! (Do not include breaks or continue functions) Write a program that asks the user to enter the amount that they budgeted for the month. A loop should then prompt the user to enter their expenses, one at a time and to enter 0 to quit. When the loop finishes, the program should display the the amount of budget left. (a negative number indicates the user is over budget and a positive number indicates the user is under...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A...
Coffee Order Structure Assignment Write a program that uses a structure for a coffee order. A coffee order consists of a double price, a string for flavor, and characters for cream (Y/N), sugar (Y/N), and coffee size (S/M/L). Your main() function will call an order function that will ask the user for the flavor, size and whether or not they want cream or sugar. Your main() function will then create a coffee order structure and assign all of the values...
Write a program in C++ coding that asks the user to input an integer between 25...
Write a program in C++ coding that asks the user to input an integer between 25 and 50, inclusive. Utilize a WHILE loop to test for INVALID input. If the input is INVALID, the loop will repeat, and ask the user to try again. The pseudocode looks like this: Prompt user to input an integer between 25 and 50 Accept the input from the user Test for invalid input (HINT: use a while loop and the OR operator with 2...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT