I have to write a program that converts numbers into roman numerals, but I'm not really sure where to go from what I have now. Anyone know how I can finish this? Im very new to this and I'm completely lost in class :(
#include<iostream>
#include<climits>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<string>
usingnamespace std;
int main(void)
{
string romnum;
unsignedshort number;
short M; // Numerical Value 1000
short D; // Numerical Value 500
short C; // Numerical Value 100
short L; // Numerical Value 50
short X; // Numerical Value 10
short IX; // Numerical Value 9
short V; // Numerical Value 5
short IV; // Numerical Value 4
short I; // Numerical Value 1
char yes_no
cout << "\nWould you like to convert numbers into Roman Numerals?";
cin >> yes_no;
cin.ignore(INT_MAX, '\n');
while ( toupper(yes_no) == 'Y' )
{
cout<< "\n\t Excelent! Let's get started!\n";
cout<< "\n\t Please enter your number:\n";
cin >> number;
if ( number >= 4000 || number <= 0 )
{
cout << "\nError. Please enter a number greater than 0 and less than
4000.\n";
}
else
{
M = number / 1000;
number = number % 1000;
D = number / 500;
number = number % 500;
C = number / 100;
number = number % 100;
L = number / 50;
number = number % 50;
X = number / 10;
number = number % 10;
IX = number / 9;
number = number % 9;
V = number / 5;
number = number % 5;
IV = number / 4;
number = number % 4;
I = number;
cout << "Thank you.\n";
}
}
cout<<"\n\t\tThank you for using the Roman Numeral Converter!!!\n";
cout << "\n\t\t\t\tHAVE A GREAT DAY!!!\n";
}
return 0;
}
short IX; // Numerical Value 9 Is not a base number, not needed
short IV; // Numerical Value 4 Is nor a base number, not needed
line 25 needs something to end the command
Remove void from main... just not needed.
54,57,60,63,66,72, and 75 need something or else the value of number will change
67 and 73 can be deleted.
Here is your hint:
Write a function that takes 2 parameters. Your roman numeral, and your variable number....
I made the small cahnges, but idk what 54,57,60,63,66,72, and 75 need. And I have no idea how to write the function that takes 2 parameters. To be honest I'm not even 100% sure how lines 49-69 work exactly and how to use them later on. My instructor just said to start it like that.
#include<iostream>
#include<climits>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<string>
usingnamespace std;
int main()
{
string romnum;
unsignedshort number;
short M; // Numerical Value 1000
short D; // Numerical Value 500
short C; // Numerical Value 100
short L; // Numerical Value 50
short X; // Numerical Value 10
short V; // Numerical Value 5
short I; // Numerical Value 1
char yes_no;
cout << "\nWould you like to convert numbers into Roman Numerals?";
cin >> yes_no;
cin.ignore(INT_MAX, '\n');
while ( toupper(yes_no) == 'Y' )
{
cout<< "\n\t Excelent! Let's get started!\n";
cout<< "\n\t Please enter your number:\n";
cin >> number;
if ( number >= 4000 || number <= 0 )
{
cout << "\nError. Please enter a number greater than 0 and less than
4000.\n";
}
else
{
M = number / 1000;
number = number % 1000;
D = number / 500;
number = number % 500;
C = number / 100;
number = number % 100;
L = number / 50;
number = number % 50;
X = number / 10;
number = number % 10;
V = number / 5;
number = number % 5;
I = number;
cout << "Thank you.\n";
}
}
cout<<"\n\t\tThank you for using the Roman Numeral Converter!!!\n";
cout << "\n\t\t\t\tHAVE A GREAT DAY!!!\n";
}
return 0;
}
None of that made sense to me. We didn't learn any of that in my class. I can use strings, looping, and branching for this program according to my instructor. So, I still have no idea what to do. Can you show me how I can complete this and explain in detail what you did? Is my original code even correct? Am i going in the right direction?
can you show me how to do that? I just got an intro to it yesterday. I still don't really know how to apply it to my program. This is extremely frustrating. I've never struggled this much in a class before to the point where I have no idea what is going on. I am losing my mind writing these programs.....@Q$TH#$QGJW#{"OTbjh