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...
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> and switch and if-else statements only. Thank you. Ex. Enter a number: 68954 Sixty Eight Thousand Nine Hundred Fifty Four Enter a number: 100000 One Hundred Thousand Enter a number: -2 Number should be from 0-1000000 only
Create a C++ program that will prompt the user to input an positive integer number and...
Create a C++ program that will prompt the user to input an positive integer number and output the corresponding number to words. Check all possible invalid input data. (Please use only switch or if-else statements. Thank you.)
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...
IN PYTHON Your task this week is to use loops to both validate user input as...
IN PYTHON Your task this week is to use loops to both validate user input as well as automate a test suite for your lab solution from last week. Your program will prompt the user for the cost of their groceries. Then you are to calculate the value of the coupon to be awarded based on the amount of the grocery bill. Use the table below to determine coupon amounts. Money Spent   Coupon Percentage Less than $10   0% From $10...
Write a program that uses input to prompt a user for their name and then welcomes...
Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.(In Python)
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...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
Design an algorithm to prompt user to enter a number. Determine the number is odd or...
Design an algorithm to prompt user to enter a number. Determine the number is odd or even with Case Logic.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT