Hello everyone,

Background: I am currently attempting a project for a professor of mine, but I cannot integrate my formula properly into my code. The project calls for a conversion from numbers to words. (I last worked in C++ a year and a half ago, so any words that don't make sense in syntax are placeholders so I understand what I was trying to do when I have a chance to look up the proper functions later) I know how I want to isolate each number, and also how to have it export it. The problem I run into is with my IF statements when I am trying to extract the respective numbers.

Assuming the number I am searching for is 15824.23, I would first take off the .23 and deal with it at the end of the equation, and then turn the 15824 -> _15 824

I would take the 824, extract the 4 through mod then divide by 10 so it would truncate off the 4, mod by 10...rinse and repeat until I got each number. After I finished my first group of 3, I would move onto my next group of 3 until I ran out of numbers to extract basically.

#include <iostream>
#include <iomanip>
#include <string>
using namespace std

int long string;
string onesA[20] = {"zero","one","two","three","four","five","six","seven","eight","nine","ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen"}
string onesB[20] = {"Zero","One","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Eleven","Twelve","Thirteen","Fourteen","Fifteen","Sixteen","Seventeen","Eighteen","Nineteen"}
string tensA[8] = {"twenty-","thirty-","fourty-","fifty-","sixty-","seventy-","eighty-","ninety-"}
string tensB[8] = {"Twenty-","Thirty-","Fourty-","Fifty-","Sixty-","Seventy-","Eighty-","Ninety-"}
string hundredsA[9] = {"one hundred","two hundred","three hundred","four hundred","five hundred","six hundred","seven hundred","eight hundred","nine hundred"}
string hundredsB[9] = {"One hundred","Two hundred","Three hundred","Four hundred","Five hundred","Six hundred","Seven hundred","Eight hundred","Nine hundred"}
string thousandsA[1] = {"one thousand"}
string thousandsB[1] = {"Thousand"}
string millionsA[1] = {"million"}
string millionsB[1] = {"Million"}
string billionsA[1] = {"billion"}
string billionsB[1] = {"Billion"}


int main()
{
	int x;
	int y;e
	int z;
	int temp;
	int n;
	
	temp = n;
	x = temp % 10;
	y = (temp / 10) % 10;
	z = (temp / 100) % 10;
	
	
	cout << "Please Enter a Number: " << endl;
	cin >> number;
	if ()
	{
		n<0;
			cout << "Invalid Number" << endl;
			cout << "Please Enter Another Number" << endl;
}
	if ()
	{
			n<=19;
			load str::ones;
			get value = n;
			
}
	if ()
	{			
			n <= 99 and n >= 20;
			load str::tens;
			get value::y
			load y
			load str::ones;
}
	if ()
	{
			n<=999 and n>=100
				load str::hundreds;
				
					
				load str::tens;
				load str::ones
			
	}
} return 0;

Any suggestions on how to best execute this would be appreciated, again I do not want the work done for me, I simply want some tips on the best ways to go about this.

Thanks,
CSStudent728

EDIT: I realize it is very incomplete what I have posted (coding wise), but I am at a roadblock at the moment and I am unsure the best way to proceed.

Edited 6 Years Ago by CSStudent728: Clarification for posting.

Hello everyone,

Background: I am currently attempting a project for a professor of mine, but I cannot integrate my formula properly into my code. The project calls for a conversion from numbers to words. (I last worked in C++ a year and a half ago, so any words that don't make sense in syntax are placeholders so I understand what I was trying to do when I have a chance to look up the proper functions later) I know how I want to isolate each number, and also how to have it export it. The problem I run into is with my IF statements when I am trying to extract the respective numbers.

Assuming the number I am searching for is 15824.23, I would first take off the .23 and deal with it at the end of the equation, and then turn the 15824 -> _15 824

I would take the 824, extract the 4 through mod then divide by 10 so it would truncate off the 4, mod by 10...rinse and repeat until I got each number. After I finished my first group of 3, I would move onto my next group of 3 until I ran out of numbers to extract basically.

<---code snipped--->

Any suggestions on how to best execute this would be appreciated, again I do not want the work done for me, I simply want some tips on the best ways to go about this.

Thanks,
CSStudent728

EDIT: I realize it is very incomplete what I have posted (coding wise), but I am at a roadblock at the moment and I am unsure the best way to proceed.

OK, you described what you do, but you didn't explain what your problem is. You need to describe your difficulty in detail, not make us read and understand your code to find flaws. You already know them. Tell us what you expected and what actually happened.

My apologies and thanks, WaltP.
As I was typing out my problem, I was breaking it down to basic elements and I figured it out on my own. Thank you Walt, for making me think about the problem in the most basic of details. I'll post back with a solution of the program if you would like to see the end result.

My apologies and thanks, WaltP.
As I was typing out my problem, I was breaking it down to basic elements and I figured it out on my own. Thank you Walt, for making me think about the problem in the most basic of details. I'll post back with a solution of the program if you would like to see the end result.

You're welcome. I suppose that was your first lesson in 'debugging'.

It's also a better way to program. Even before sitting in front of the computer, break your problem down to it's smallest details on paper, then put it back together as sort-of-code (pseudo-code). Then take that map to the computer and write the code. Programming will go faster with fewer logic problems.

This article has been dead for over six months. Start a new discussion instead.