473,657 Members | 2,592 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 6311
> 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******@bassb erry.com> wrote in message news:34******** *************** ***@posting.goo gle.com...
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
10313
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 character which is represented by the number( in this example, it would be the hardcoded character © the copyright character) for output.
4
11499
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 should have sufficed (of course it is the responsibility of the person performing the Load to ensure that the character he has chosen as column delimiter does not exist as a part of data). The problem I am facing is that I have a file generated...
11
28250
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 question, but where is the FAQ section of the
5
6650
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 *s) { char *x;
18
4612
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 has some different characters in it that I am trying to remove. The small a with two dots over it and the small y with two dots over it. Here is my code so far to remove the small y: Private Sub Button2_Click(ByVal sender As System.Object, ByVal...
12
8535
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 the array when printed would equal the rpm value ie 2031.00 rpm = I've been rummaging everywhere and can't find anything to tackle this. I would be extreemly greatful to anyone that can point me in the right
2
10295
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 WebSphere Application Server. I have two questions: 1. How many characters, such as Chinese, Japanese, can a CHAR(128) or
4
2729
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 in Javascript? Jas
17
10652
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 talking with another team -- codepage -- at the same time. I am more confused when I saw sometimes we need codepage parameter for wide character conversion, and sometimes we do not need for conversion. Here are two examples,
3
2472
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 dates/times, and is used by a number of other programs as well. I need to convert times that use this convention to python time representations, and because Python does not support the %z time conversion character I cannot simply use the time.strptime...
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8845
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7355
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5647
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2745
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 we have to send another system

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.