do you think this needs another function for operator
Robert Ryan <[EMAIL PROTECTED]> wrote: I am
resending the code, there is only 1 main
#include<iostream>
using namespace std;
int get_Roman_token() { };
int roman_to_int(char c)
{
char roman = c;
roman = toupper(roman);
if (roman == 'I') return 1;
else if(roman == 'V') return 5;
else if (roman == 'X') return 10;
else if (roman == 'L') return 50;
else if (roman == 'C') return 100;
else if (roman == 'C') return 100;
else if (roman == 'D') return 500;
else if (roman == 'M') return 1000;
else
{
cout << "That is not a Roman numeral." << endl;
return -1;
}
}
int main()
{
char Roman; int value, c1, c2, first, second;
cout <<"Enter a Roman Numeral to be converted to a decimal: ";
while(cin >> Roman)
{
{
int temp = roman_to_int(Roman);
if (temp > 0)
cout << temp << endl;
cin >> c1;
if(c1== '.')
return 0;
else
first = roman_to_int(c1);
cin >> c2;
if(c2 == '.')
{
cin.putback(c2);
return first;
}
else
second = roman_to_int(c2);
if (second > first)
return second - first;
else
cin.putback(c2);
return first;
}
cout << "Enter a Roman Numeral: ";
while(cin)
{
int temp = get_Roman_token() ;
if (temp != 0 )
value = value + temp;
else
{
cout<<value;
int value = 0;
}
}
}
vi Hw3#6.cpp
g++ Hw3#6.cpp
./a.out
Enter a Roman Numeral to be converted to a decimal:
Thomas Hruska <[EMAIL PROTECTED]> wrote: Robert
Ryan wrote:
>
> I don't see where the result comes from.
> thanks
> bob
> Modify 2.5 to accept input in Roman numerals
> using get_Roman_token(). For example,
>
> II.+III. =5
> IX.-II. =7
> IV.*XI. =44
>
> // 2. 5
>
> #include<iostream>
> using namespace std;
> int main()
> {
> double double1, double2; char operation;
> cout << "Enter a double and an operation followed\n ";
> cout << "by another double.\n ";
> cin >> double1 >> operation >> double2;
> if(operation == '+')
> cout << double1 << operation << double2
> << "=" << double1 + double2 << "\n";
> if(operation == '-')
> cout << "=" << double1 - double2 << "\n";
> if(operation == '*')
> cout << "=" << double1 * double2 << "\n";
> if(operation == '/')
> cout << "=" << double1 / double2 << "\n";
> return 0; }
>
> int main()
> {
<snip>...
>
> }
>
> int main()
> {
> char Roman;
> int value = 0;
>
> cout <<"Enter a Roman Numeral: " ;
> while(cin)
> {
>
> int temp = get_Roman_token() ;
> if (temp != 0 )
> value = value + temp;
> else
> {
> cout<<value;
> value = 0;
> }
> }
> }
<snip several more main()'s>
> vi Hw3#6.cpp g++ Hw3#6.cpp
> ./a.out
> Enter a Roman Numeral to be converted to a decimal: II. + II.
> 1
> That is not a Roman numeral.
> That is not a Roman numeral.
Huh? How in the world did that code compile?
--
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197
*NEW* MyTaskFocus 1.1
Get on task. Stay on task.
http://www.CubicleSoft.com/MyTaskFocus/
---------------------------------
Looking for last minute shopping deals? Find them fast with Yahoo! Search.
[Non-text portions of this message have been removed]
---------------------------------
Never miss a thing. Make Yahoo your homepage.
[Non-text portions of this message have been removed]