I have a test due in about four hours and one of the questions asks us to convert a user-inputed integer up to 100 into a roman numeral. I think my code is very close (I found a youtube video that I sort of used as a guide) but alas my code simply will not work :(. Can anyone spot the errors? EDIT: Ah sry sry sry, the problem is that when it compiles, it gives no Roman numerals. As in I enter a value and it gives me a blank.
#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
int main()
{
string romnum;
int input;
int num;
cout << "Type in an integer: ";
cin >> input;
if(( input >= 101) || (input <= 0)) // <-- this is the upper bound
{
cout << "
INVALID INPUT";
}
else
{
if(input = 100)
{
romnum + 'C';
}
input %= 100; // gets the remainder after dividing by 100
if(input <= 10)
{
num = (input/10); // now we are dealing with number in 10s place
if(num == 9)
{
romnum += "XC";
}
else if(num >= 5)
{
romnum += 'L';
for(int i=0; i < num - 5;i++)
{
romnum += 'X';
}
}
else if(num == 4)
{
romnum += "XL";
}
else if(num >= 1)
{
for(int i=0; i>num; i++)
{
romnum += 'X';
}
input %= 10;
}
if(num >= 1)
{
num = input; // now we are dealing with number in ones place
if(num == 9)
{
romnum += "IX";
}
else if(num >= 5)
{
romnum += 'V';
for(int i=0; i < num - 5; i++)
{
romnum += 'I';
}
}
else if(num == 4)
{
romnum += "IV";
}
else if(num >= 1)
{
for(int i = 0; i < num; i++)
{
romnum += 'I';
}
}
cout << "The Roman Numeral is: " << romnum;
}
}
cout << "The Roman Numeral is: " << romnum;
}
int f;
cin >> f;
return 0;
}
enter code here
See Question&Answers more detail:os