473,506 Members | 17,000 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Character to number conversion

I am trying to write a program the converts letters to
numbers. My attached code works for the first letter
entered but will not read past the first number. Please
help.

Thanks.

#include <iostream>
#include <string>

using namespace std;

void convertnum (char, int&);

int main()
{
char firstnum;
//char secnum;
int firstconv = 0;
//int secconv;
cout << " Please enter the first number: " << endl;
cin >> firstnum;

convertnum (firstnum, firstconv);

cout << " The first number is: " << firstconv <<
endl;
return 0;
}

//************************************************** *******
**************************************

void convertnum(char rnum, int& numconv)
{
numconv = 0;

if (rnum == 'M' || rnum == 'm')
numconv += 1000;
if (rnum == 'D' || rnum == 'd')
numconv += 500;
if (rnum == 'C' || rnum == 'c')
numconv += 100;
if (rnum == 'L' || rnum == 'l')
numconv += 50;
if (rnum == 'X' || rnum == 'x')
numconv += 10;
if (rnum == 'V' || rnum == 'v')
numconv += 5;
if (rnum == 'I' || rnum == 'i')
numconv += 1;

}
Jul 19 '05 #1
2 6303
> I am trying to write a program the converts letters to
numbers. My attached code works for the first letter
entered but will not read past the first number. Please
help.


Look up "while" and "for" in your book/website.
Jonathan
Jul 19 '05 #2

"cbing" <cb******@bassberry.com> wrote in message news:34**************************@posting.google.c om...
I am trying to write a program the converts letters to
numbers. My attached code works for the first letter
entered but will not read past the first number. Please
help.

That's all it does. It reads one char, converts it, outputs
it, and then returns from main. Perhaps you wanted a loop?
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
10279
by: Andrzej Jan Taramina | last post by:
I have a need to convert a number into the character that it represents. For example, if I have: <xsl:variable name="number" select="169"/> I want to be able to convert this to the...
4
11467
by: Raquel | last post by:
Could someone explain to me what the reason is for having a character delimiter (which is double quotes by default) for performing Loads/Imports on UDB? I would think that column delimiter along...
11
28224
by: Mars | last post by:
char c; int i; scanf("%d",&i); c=getchar(); I want to read a integer and a character in 2 lines. Why the getchar always get the \n character from the last line????? (Sorry for my newbie...
5
6632
by: Stefan Krah | last post by:
Hello, I am currently writing code where it is convenient to convert char to int . The conversion function relies on a character set with contiguous alphabets. int set_mesg(Key *key, char...
18
4582
by: james | last post by:
Hi, I am loading a CSV file ( Comma Seperated Value) into a Richtext box. I have a routine that splits the data up when it hits the "," and then copies the results into a listbox. The data also...
12
8528
by: nikNjegovan | last post by:
So i have a tachometer that I can communicated with via UART which gives me a character array of ascii values in the following form: Standard ascii 7 characters including decimal point such that...
2
10267
by: Jason | last post by:
Hi, I was wondering if anyone could advise me on this. Right now I am setting up a DB2 UDB V8.2.3 database with UTF8 character set, which will work with a J2EE application running on...
4
2716
by: Jason | last post by:
This is a Chinese character in unicode: 挪 I made it in Javascript by adding "&#"+"25"+"386" I need to convert it in Javascript to this: 挪 (The actual character) How do I achieve this conversion...
17
10613
by: =?Utf-8?B?R2Vvcmdl?= | last post by:
Hello everyone, Wide character and multi-byte character are two popular encoding schemes on Windows. And wide character is using unicode encoding scheme. But each time I feel confused when...
3
2462
by: Evan Klitzke | last post by:
Although it is not present in ANSI C, the GNU version of stftime supports the conversion character %z, which is a time offset from GMT. The four digit time offset is required in RFC 2822...
0
7103
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7478
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
409
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.