C
cbing
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;
}
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;
}