Question

Write a program in C# that allows any number of values between 0 and 10 to...

Write a program in C# that allows any number of values between 0 and 10 to be entered. When the user stops entering the values, display a frequency distribution bar chart. Use asterisks to show the number of times each value was entered. If a given number is not entered, no asterisks should appear on that line. Your application should display error messages if a value outside the acceptable range is entered or if a non-numeric character is entered.

Homework Answers

Answer #1

using System;
class AstricPattern{
static void Main(){
Console.WriteLine("-1 for the exist the loop");
int[] frq={0,0,0,0,0,0,0,0,0,0};
while(true){
int value;
string userValue=Console.ReadLine();
bool success = int.TryParse(userValue, out value);
if(success){
if(value==-1){break;}
if(value>=1 && value<=10){
frq[value-1]=frq[value-1]+1;
}
else{
Console.WriteLine("Invalid range");
}
}else{
Console.WriteLine("Invalid input");
}
}
for(int i=0;i<10;i++){
Console.Write((i+1)+" | ");
for(int j=0;j<frq[i];j++){
Console.Write("*");
}Console.WriteLine("");
}
}
}

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
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Write a program that asks the user for a number in the range 1 through 12....
Write a program that asks the user for a number in the range 1 through 12. The program should display the corresponding month of the year, where 1 = January, 2 = February, 3 = March, 4 = April, 5 = May, 6 = June, 7 = July, 8 = August, 9 = September, 10 = October, 11 = November, and 12 = December. The program should display an error message if the user enters a number that is outside...
C++ please Write a program that allows a user to enter any number of product prices...
C++ please Write a program that allows a user to enter any number of product prices and show the total of all of the products. Use 0.00 as a sentinel value. (while loop)
in C++ Write a program. The program should prompt the user for the number of shares...
in C++ Write a program. The program should prompt the user for the number of shares purchased, purchase price per share, the commission for the purchase, sale commission paid, and the price the shares were sold at. The program should validate each of these values to ensure they are acceptable (none can be less than zero) and should then pass them to a function called numberfunction.The function should use the following formula to determine the profit: Profit = ((number of...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional...
Write a program that allows two players to play a game of tic-tac-toe. Use a twodimensional char array with three rows and three columns as the game board. Each element in the array should be initialized with an asterisk (*). The program should run a loop that: • Displays the contents of the board array. • Allows player 1 to select a location on the board for an X. The program should ask the user to enter the row and...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise...
Data Encryption (Strings and Bitwise Operators) Write a C program that uses bitwise operators (e.g. bitwise XOR) to encrypt/decrypt a message. The program will prompt the user to select one of the following menu options: 1. Enter and encrypt a message 2. View encrypted message 3. Decrypt and view the message (NOTE: password protected) 4. Exit If the user selects option 1, he/she will be prompted to enter a message (a string up to 50 characters long). The program will...
Color. Write a program that displays the color of the camera whose item number is entered...
Color. Write a program that displays the color of the camera whose item number is entered by the user. All item numbers contain exactly seven characters. All items are available in four colors: black, green, red, and white. The fourth character in the item number indicates the item’s color, as follows: a B or b indicates Black, a G or g indicates Green, an R or r indicates Red, and a W or w indicates White. If the item number...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer...
Question: Squares. Write a program class named SquareDisplay that asks the user for a positive integer no greater than 15. The program should then display a square on the screen using the character ‘X’. The number entered by the user will be the length of each side of the square. For example, if the user enters 5, the program should display the following:       XXXXX       XXXXX       XXXXX       XXXXX       XXXXX INPUT and PROMPTS. The program prompts for an integer as follows: "Enter...
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2....
Write a program display the following menu: Ohms Law Calculator 1. Calculate Resistance in Ohms 2. Calculate Current in Amps 3. Calculate Voltage in volts 4. Quit Enter your choice (1-4) If the user enters 1, the program should ask for voltage in Volts and the current in Amps. Use the following formula: R= E/i Where: E= voltage in volts I= current in amps R= resistance in ohms If the user enters 2 the program should ask for the voltage...
Develop a C++ program that determines the largest and second largest positive values in a collection...
Develop a C++ program that determines the largest and second largest positive values in a collection of data Prompt the user to enter integer values until they enter any negative value to quit You may presume the user will input at least two valid integer values Create a loop structure of some sort to execute this input cycle Maintain the largest and second largest integer as the user inputs data This logic should be placed inside your loop structure Arrays...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT