Help with a c++ program that converts numbers 1 to 1000

  • Context: C/C++ 
  • Thread starter Thread starter mulabisc
  • Start date Start date
  • Tags Tags
    C++ Numbers Program
Click For Summary
SUMMARY

The discussion focuses on improving a C++ program that converts integers from 1 to 1000 into Roman numerals. The initial code provided by the user contains logical errors and lacks comprehensive handling for all numbers in the specified range. Key Roman numeral representations include 1-3 as "I", "II", "III", 4 as "IV", 5 as "V", 9 as "IX", and multiples of ten such as 10 as "X", 50 as "L", 100 as "C", 500 as "D", and 1000 as "M". The user is advised to implement a systematic approach using conditional statements to categorize numbers based on their value.

PREREQUISITES
  • Understanding of C++ syntax and structure
  • Knowledge of conditional statements (if-else) in programming
  • Familiarity with Roman numeral conventions
  • Basic input/output operations in C++ using cin and cout
NEXT STEPS
  • Implement a complete conversion function for all numbers from 1 to 1000 in C++
  • Learn about using arrays or strings to store Roman numeral representations
  • Explore modular arithmetic to simplify the conversion process
  • Research error handling techniques in C++ for user input validation
USEFUL FOR

C++ developers, computer science students, and anyone interested in algorithm design for numeral conversion.

mulabisc
Messages
3
Reaction score
0
I have tried to come up with the code below so i want to improve it so tha it converts numbers 1 to 1000 to romans.. help out!


#include <iostream>
using namespace std;

int main()
{

int n;
n >=1;

count<< "please enter an interger number:" <<endl;
cin >> n;

if(n == 9)

count << "IX";

else if(n >=5 && n<=8)

count << "V";

else if (n == 4)

count << "IV";


else if(n >=1 && n <=3)

count << "I";




return 0;
}
 
Technology news on Phys.org
http://maryt.files.wordpress.com/2007/03/roman_numerals_complete.jpg

It says

10 - X
50 - L
100 - C
500 - D
1000 - M

and second thing to notice is

20 = XX
30 = XXX
40 = XL

60 = LX
70 = LXX
80 = LXXX
90 = XC

and numbers from 1 to 9 just use I,II,III, .. with a prefix
like 20 = XX
and 21 = "XX"+ "I"


so .. get the number as a factor of 10 first .. and see to which group it belongs (using ifs.. etc)

Need to store:
I,II,III... IX
and
X,L,C,D,M
 
Last edited by a moderator:

Similar threads

Replies
12
Views
2K
  • · Replies 6 ·
Replies
6
Views
12K
  • · Replies 39 ·
2
Replies
39
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 15 ·
Replies
15
Views
4K
  • · Replies 40 ·
2
Replies
40
Views
4K
  • · Replies 22 ·
Replies
22
Views
4K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 10 ·
Replies
10
Views
1K
  • · Replies 118 ·
4
Replies
118
Views
10K