Question

In: Computer Science

Prompt the user to input their lucky number. Upon getting the users input, validate that the...

Prompt the user to input their lucky number. Upon getting the users input, validate that the input is a valid number using Int32.TryParse (more info can be found at https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/types/how-to-convert-a-string-to-a-number (Links to an external site.)). If the input is not a valid number, output a message to the user stating that you are sorry but you are unable to run the FizzBuzz process due to the input not being a valid number. If the input is valid, you are clear to start the FizzBuzz process. If the input is divisible by 3, then output {number} Fizz. If the input is divisible by 5, then output {number} Buzz. If the input is divisible by 3 AND 5, output {number} FizzBuzz. If it is not divisible by either 3 or 5, simply just output the number.

Solutions

Expert Solution

/* Please read the comments and see the output*/

using System;

using System.IO;

class FizBuzz

{

    public static void Main() {

        string input; // For reading input

        int num;      // To store the int value if input is valid

        bool isValidInput;  // Boolean variable to check input is valid is or not

        do {

            Console.WriteLine("Enter Lucky Number: ");

            input  = Console.ReadLine(); // Read user input

            isValidInput = int.TryParse(input,out num); // Check input is integer or not

            if(!isValidInput)  // If input is not valid, show error message

                Console.WriteLine("you are sorry but you are unable to run the FizzBuzz process due to the input not being a valid number.");

        }while(!isValidInput);  // Run this until, user give correct input

        string result =""; // Variable to keep the result for the valid input integer

         if(num % 15 == 0)  result = num + "  FizzBuzz"; // DECIDE parameter for BUZ FIZZ GAME

        else if(num % 3 == 0 )  result = num + " Fizz";

        else if(num % 5 == 0)  result = num + " Buzz";

        else result = ""+ num;

        Console.WriteLine(result);   // Show the result

        Console.WriteLine("PRESS enter for exit"); // Exit of game

        Console.ReadLine();

    }

}

/* OUTPUT*/


Related Solutions

Prompt the user for their name, get and store the user input. Prompt the user for...
Prompt the user for their name, get and store the user input. Prompt the user for their age, get and store the user input. We will assume that the user will enter a positive integer and will do no error checking for valid input. Determine and store a movie ticket price based on the user's age. If their age is 12 or under, the ticket price is $5. If their age is between 13 and 64, inclusive, the ticket price...
Create a C++ program that will prompt the user to input an integer number and output...
Create a C++ program that will prompt the user to input an integer number and output the corresponding number to its numerical words. (From 0-1000000 only) **Please only use #include <iostream>, switch and if-else statements only and do not use string storing for the conversion in words. Thank you.** **Our class is still discussing on the basics of programming. Please focus only on the basics. Thank you.** Example outputs: Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four...
Print greeting Prompt the user for starting odometer reading Use a while loop to validate that...
Print greeting Prompt the user for starting odometer reading Use a while loop to validate that starting odometer reading is a positive number. Initialize variables: last odometer reading, current odometer reading, leg number, total fuel, moreInput While moreInput == ‘y’ Prompt the user for new odometer reading and fuel consumed If fuel is positive and new odometer reading > last odometer reading: Calculate MPG for this leg using mpg = (new odometer – last odometer) / fuel Print MPG for...
Please assist with getting my code to correctly check to validate input. Everything else works fine,...
Please assist with getting my code to correctly check to validate input. Everything else works fine, but when I enter a character, it should say Invalid entry. Everything else should also work. It should not allow more or less than 9 digits, and it should ask again for input if it doesn't like the input. Please help my code and explain how it is working. I also need to keep the recursive function. #include <stdio.h> #include <ctype.h > int SecNumSum(long...
In Python, your program will read in a number (no need to prompt the user), and...
In Python, your program will read in a number (no need to prompt the user), and then reads in that number of lines from the terminal. Then the program should print an array of strings formatted in a nice regular box. So if the user inputs this: 5 Grim visaged war has smooth’d his wrinkled front And now, instead of mounting barded steeds To fright the souls of fearful adversaries He capers nimbly in a lady’s chamber To the lascivious...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the maximum number (as integer) Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array Write a method named printTable to print out the MulitTable, with the following header, public static void printTable(int[][] multitable) In printTable(), when the value of the MultiTable is an odd number, print out Z Must use...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
Python #Use an input statement to ask the user for his/her age (no prompt) and assign...
Python #Use an input statement to ask the user for his/her age (no prompt) and assign the user entry to a variable #Convert the user input to an integer and assign to a variable #Write if-elif-else statements with the following conditions and actions #Important: For each Action below, use the same variable name for the rating in all the if, elif, and else statements #Condition: user input less than or equal to 9 Action: assign the letter G as a...
4. Prompt user to enter a double number from console. Round this number so it will...
4. Prompt user to enter a double number from console. Round this number so it will keep 2 places after the decimal point. Display new number. For example, number 12.3579 will round to 12.36; number 12.4321 will round to 12.43 This is meant to be written in Java 14.0
Prompt the user to enter an integer Then, prompt the user to enter a positive integer...
Prompt the user to enter an integer Then, prompt the user to enter a positive integer n2. Print out all the numbers that are entered after the last occurrence of n1 and whether each one is even or odd If n1 does not occur or there are no values after the last occurrence of n1, print out the message as indicated in the sample runs below. Sample: Enter n1: -2 Enter n2: 7 Enter 7 values: -2 3 3 -2...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT