Hi you guys, just want how do you convert a number to word in c++ if it is in the thousands?:?:

Recommended Answers

All 5 Replies

#include "hps.h"
#include <iostream>
#include <string>
#include <conio.h>
using namespace std;

main(){
	hps x;
	long x1 = 0, x2=0 ,pick,getnext;
	char *pr,ix[200];
	cout<<"Enter number to convert:";
	cin>>ix;pr=ix;pick=atol(pr);
	long z1=0;
	long z2=0;
	z1 =pick /1000;
	getnext = z1 * 1000;
	if (z1 > 0 && z1 < 21 || z1 == 20 || z1 == 30 || z1 == 40 || z1 == 50 || z1 == 60 || z1 == 70 || z1== 80 || z1 == 90){
		x.initno(z1);
		cout<<" Thousand";
	}
	else{
		if(z1 > 20){
			z2 = z1 /10;
			z2 = z2 * 10;
			x.initno(z2);
			z2 = z1 % 10;
			x.initno(z2);
			cout<<" Thousand";
		}
	}

	long y1=0, newx;
	newx = pick - getnext;
	y1 = newx / 100;
	if(y1 > 0) x.hdred(y1);
	x1 = pick % 100;
	if (x1 > 0 && x1 < 21 || x1 == 20 || x1 == 30 || x1 == 40 || x1 == 50 || x1 == 60 || x1 == 70 || x1== 80 || x1 == 90){
		x.initno(y1);
	}else{
		if(x1 > 20){
			x2 = x1 / 10;
			x2 = x2 * 10;
			x.initno(x2);
			x2 = x1 % 10;
			x.initno(x2);
		}
	}
	cout<<endl;
	getche();
	return;
}

Please Edit your current post. Your source code must be surounded with bb code tags,
For example,

[code=cplusplus] // statements [/code]

There is a header called sstream which is very handy in these types of situations. Here is an example, although not compiled.

#include<iostream>
#include<sstream>

using namespace std;

int main()
{
    stringstream convert;
    string result;
    int num = 12345;
    convert << num;
    convert >> result;
    cout<<result<<endl;

   return 0;
}

Thanks for the reply, it really helped me a lot...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.