Question

In: Computer Science

Write a program that prompts a user for an integer from 1 to 99 and prints...

Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words.
The program will loop in case the user wants to input an additional number.
If the user enters -99, the program will exit.

Example:
Input: 89
Output: Eighty nine

Input: 45
Output: Fourty five

Input: -99
Output: Have a nice day.
<program exits>

For this project, you are to:
1) You should validate any data coming from the user (number should be within 1-99)
2) Please add comments as appropriate, and use good coding styles (proper indenting and naming conventions as has been discussed in class).
THE TOP OF FILE SHOULD CONTAIN YOUR NAME, CLASS/SECTION and brief description of your class
3) This assignment is to be worked on individually and not in groups.
4) YOU SHOULD SUBMIT ONE file - a MS Word file which contains:
a) Your code (cut & pasted your .cpp file into MS Word and do not use a screenshot for this)
b) Multiple screenshots showing your program running AND tested with different input data.

*** PLease ensure you write YOUR OWN CODE as Blackboard will indicate any simularities to inside LAGCC and outside.

C++

Solutions

Expert Solution

C++ code:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
//under twenty number
string und_twenty[20] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"};
//under hundred numbers
string und_hundred[8] = {"Twenty","Thirty","Forty","Fifty","Sixty","Seventy","Eighty","Ninety"};
string convert(int n){
if(n>=20){
return " " + und_hundred[n/10-2] + convert(n%10);
}
else if(n>=1){
return " " + und_twenty[n];
}
return " ";
}
int main() {
   int n;
   cin>>n;
   while(n!=-99){
   // if n is valid then convert it to word form
   if(n>=1&&n<=99){
   string ans = convert(n);
   cout<<ans.substr(1)<<'\n';
   }
   cin>>n;
   }
   cout<<"Have a nice day.\n";
   return 0;
}


Related Solutions

Write a program that prompts a user for an integer from 1 to 99 and prints...
Write a program that prompts a user for an integer from 1 to 99 and prints it as an amount in words. The program will loop in case the user wants to input an additional number. If the user enters -99, the program will exit. Example: Input: 89 Output: Eighty nine Input: 45 Output: Fourty five Input: -99 Output: Have a nice day. <program exits> c++ project. need help.
Write a program which prompts the user for a positive integer, and then prints out the...
Write a program which prompts the user for a positive integer, and then prints out the prime factorization of their response. Do not import anything other than the Scanner. One way you might go about this using nested loops: Start a "factor" variable at 2 In a loop: repeatedly print the current factor, and divide the user input by it, until the user input is no longer divisible by the factor increment the factor This plan is by no stretch...
in C++ programing language Write a program that prompts the user for an integer, then prints...
in C++ programing language Write a program that prompts the user for an integer, then prints all of the numbers from one to that integer, separated by spaces. Use a loop to print the numbers. But for multiples of three, print "Fizz" instead of the number, and for the multiples of five print "Buzz". For numbers which are multiples of both three and five print "FizzBuzz". Drop to a new line after printing each 20 numbers. If the user typed...
Write a program that prompts the user to enter an integer from 1 to 15 and...
Write a program that prompts the user to enter an integer from 1 to 15 and displays a pyramid, as shown in the following sample run: here............THE PYRAMID HAS TO BE THIS SHAPE AND IT IS DONE IN JAVA PLEASE 7 6 5 4 3 2 1 2 3 4 5 6 7 6 5 4 3 2 1 2 3 4 5 6 5 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4...
Write a program that asks the user for an integer. The program checks and prints to...
Write a program that asks the user for an integer. The program checks and prints to the screen whether the number is prime or not. For example, if user enters 17, the program should print “17 is prime”; if the user enters 20, the program should print “20 is not prime”. please do it with a “ while Loop”, Thanks..
Problem 1 Write a program that prompts the user to enter an integer It then tells...
Problem 1 Write a program that prompts the user to enter an integer It then tells the user if the integers is a multiple of 2, 3, 5, 7 or none of the above. Program language is C Ex. Enter an integer 12 You entered 12 The number you entered is a multiple of 2 ----------------------------------------------- Enter an integer 11 You entered 11 The number you entered is not a multiple of 2, 3, 5, or 7
Write a Java program that prompts the user to input a string and prints whether it...
Write a Java program that prompts the user to input a string and prints whether it is a palindrome. A palindrome is a string which reads the same backward as forward, such as Madam (disregarding punctuation and the distinction between uppercase and lowercase letters). The program must use the stack data structure. The program must include the following classes: The StackX class (or you can use the Java Stack class). The Palindrome class which must contain a method named palindrome()...
Write a program that prompts the user to enter a positive integer and then computes the...
Write a program that prompts the user to enter a positive integer and then computes the equivalent binary number and outputs it. The program should consist of 3 files. dec2bin.c that has function dec2bin() implementation to return char array corresponding to binary number. dec2bin.h header file that has function prototype for dec2bin() function dec2binconv.c file with main function that calls dec2bin and print results. This is what i have so far. Im doing this in unix. All the files compiled...
Problem 4 : Write a program that prompts the user to enter in an integer and...
Problem 4 : Write a program that prompts the user to enter in an integer and then prints as shown in the example below Enter an integer 5 // User enters 5 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5 Bye
Write a program which: Prompts the user for a positive integer >= 0 Validates the user...
Write a program which: Prompts the user for a positive integer >= 0 Validates the user input to ensure it is a positive integer >= 0 Allocate (dynamically) an array big enough for the data. Load the array with random numbers ranging in value from1 to 100 Display the elements of the array (unsorted) Display the elements of the array (sorted) Display the average Display the median Display the mode, if none, display appropriate message RESTRICTIONS No global variables No...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT