Help me fix my code. I have a problem my code when I input 112 output one hundred twelve two
I want fix when I put 112 out one hundred twelve.
Homework Write a program that reads a whole number of up to nine digits and prints it in words. For example, the input 13247 ought to produce "thirteen thousand two hundred forty seven"
Please use my code. Thank you so much
#include <iostream>
using namespace std;
void breakapart(int n, int &a, int &b, int &c);
void writeNum(int digit);
void writeSingle(int n);
void writeTens(int tensD, int onesD);
int main()
{
int num, first, second, third;
cout<<"Input a 9 digit number "<<endl;
cin>>num;
// Break the number into three three-digit numbers
breakapart(num,first,second,third);
writeNum(first);
// If number is above or equal to one million, print name million
if(num>=1000000)
{
cout<<"million ";
}
writeNum(second);
// If number second in break not equal to 0, print name thousand
if(second!=0)
{
cout<<"thousand ";
}
writeNum(third);
return 0;
}
//Break the number into three three-digit numbers
void breakapart(int n, int &a, int &b, int &c)
{
c = n%1000;
n = n/1000;
b = n%1000;
n = n/1000;
a = n%1000;
n = n/1000;
}
// Read number one digit
void writeSingle(int digit)
{
switch(digit)
{
case 1: cout<<"one "; break;
case 2: cout<<"two "; break;
case 3: cout<<"three "; break;
case 4: cout<<"four "; break;
case 5: cout<<"five "; break;
case 6: cout<<"six "; break;
case 7: cout<<"seven "; break;
case 8: cout<<"eight "; break;
case 9: cout<<"nine "; break;
}
}
// Read number ten digit
void writeTens(int tensD, int onesD)
{
switch(tensD)
{
case 1:
switch(onesD)
{
case 0: cout<<"ten "; break;
case 1: cout<<"eleven "; break;
case 2: cout<<"twelve "; break;
case 3: cout<<"thirteen "; break;
case 4: cout<<"fourteen "; break;
case 5: cout<<"fifteen "; break;
case 6: cout<<"sixteen "; break;
case 7: cout<<"seventeen "; break;
case 8: cout<<"eighteen "; break;
case 9: cout<<"nineteen "; break;
}
break;
case 2: cout<<"twenty "; break;
case 3: cout<<"thirty "; break;
case 4: cout<<"forty "; break;
case 5: cout<<"fifty "; break;
case 6: cout<<"sixty "; break;
case 7: cout<<"seventy "; break;
case 8: cout<<"eighty "; break;
case 9: cout<<"ninty "; break;
}
}
void writeNum(int n)
{
// break number into single digit
int one, two, three;
three = n%10;
n = n/10;
two = n%10;
n = n/10;
one = n;
writeSingle(one);
// If number one above equal to 0, print name hundred
if(one > 0)
{
cout<<"hundred ";
}
writeTens(two, three);
writeSingle(three);
}
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps with 1 images
- Please run this on linux, compile and look at the placement for row "Tangent". Match the numbers below tangent and make sure all the other row numbers are lining up with the other headings main.c #include <stdio.h>#include <math.h> #define M_PI 3.14159265358979323846 /** * Given a incrementVal value, this function will print a table of trigonometric values * from 0 to 360, in increments of the incrementVal value. * For example, if the incrementVal value is 90, the table will print values for 0, 90, 180, 270 and 360. * incrementVal - the degree value to use for the increment*/void displayTriTab(int incrementVal) { //Display the header for the table printf("\n\t--- TRIGONOMETRIC TABLE ---\n\n"); // Display the column headings for the table printf("%3s%10s%10s%10s%10s\n", "Degrees", "Radians", "sine", "cosine", "tangent"); printf("%3s%10s%10s%10s%10s\n", "-------", "-------", "------", "-------", "-------"); //Declare variables for radians, sine cosine,…arrow_forwardAccumulating Totals in a Loop Summary In this lab, you add a loop and the statements that make up the loop body to a Java program that is provided. When completed, the program should calculate two totals: the number of left-handed people and the number of right-handed people in your class. Your loop should execute until the user enters the character X instead of L for left-handed or R for right-handed. The inputs for this program are as follows: R, R, R, L, L, L, R, L, R, R, L, X Variables have been declared for you, and the input and output statements have been written. Instructions Ensure the file named LeftOrRight.java is open. Write a loop and a loop body that allows you to calculate a total of left-handed and right-handed people in your class. Execute the program by clicking Run and using the data listed above and verify that the output is correct.arrow_forwardUse Python code with: "def recolorImage(img,color):" without using cv2 or PIL recolor(img, color) - Changes all non-white pixels of the image referred to by the parameter img to the specified color, and returns a new image with the changes. img is a 2D array of RGB pixels which represent images. color is a list containing 3 integers, each from 0 to 255, representing RGB values. To create a new image use the cmpt120image.getBlackImage() function which returns a new canvas to draw on.arrow_forward
- Use cin to read integers from input until 1000 is read. For each remaining integer read before 1000, if the integer is positive, output the integer followed by a newline and add the integer to totalOfSelected. Ex: If the input is 8 24 15 -6 14 1000, then the output is: 8 24 15 14 The sum of all positive values is 61 #include <iostream> using namespace std; int main() { int inputValue; int totalOfSelected; /* Your code goes here */ cout << "The sum of all positive values is " << totalOfSelected << endl; return 0; }arrow_forwardNEED C++ HELP WITH WRITING VECTORS WITH CLASSES Write code to read a list of song durations and song names from input. For each line of input, set the duration and name of currSong. Then add currSong to playlist. Input first receives a song duration, then the name of that song (which you can assume is only one word long). Input example: 424 Time383 Money-1 CODE AS IS NOW #include <iostream>#include <string>#include <vector>using namespace std; class Song { public: void SetDurationAndName(int songDuration, string songName) { duration = songDuration; name = songName; } void PrintSong() const { cout << duration << " - " << name << endl; } int GetDuration() const { return duration; } string GetName() const { return name; } private: int duration; string name;}; int main() { vector<Song> playlist; Song currSong; int currDuration; string currName; unsigned int i;…arrow_forward//Can you please debug this program. Thank you #include<stdio.h>#include<stdlib.h> //This function takes n and k and computes n using Pascal’s Rule.long choose(int n, int k); //This functions below create a memoization table containing//long values of dimension (n+1)×(k+1) long chooseWithMemoization(int n, int k); //This is a new recursive function that also takes the table as a parameter.//When the function needs to compute (n , k )it checks the table first, and//if the value has already been comput(is not -1) then it returns that value. long chooseWithMemoizationRecursive(int n, int k, long **tableau); int main(int argc, char **argv) {//variable declaration int n; int k; scanf("%d",&n); scanf("%d",&k ); long choice = -1;//printing out the out put choice = chooseWithMemoization(n,k); printf("choose(%d,%d) = %ld\n", n, k, choice); return 0;} /** * This function takes n and k and computes n using Pascal’s Rule.*/long choose(int…arrow_forward
- Python (this is not graded this is practice work that is not graded) write and test a function which takes two dates (month, day) list arguments.When the function is called with the two arguments, it returns the number of days betweenthose two dates. Print the returned value. It is assumed that the first date occurs first. Forinstance, if the users calls the function with FUNCTION([12, 10], [12, 20]) as arguments, thereturned value is 10 days. However, if FUNCTION([12, 20], [12, 10]) is called, the returnedvalue is -10 days.Assume February has 28 days.Test data: [10, 30], [5, 20] [1, 30], [5, 25] [5, 25], [1, 30] [1, 1], [12, 31]arrow_forwardUse a while loop function instead of a for loop sing pythonarrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY