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

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

Discussion Overview

The discussion revolves around a C++ program intended to convert numbers from 1 to 1000 into their Roman numeral representations. Participants are addressing the implementation details and potential improvements for handling a broader range of numbers.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant shares a C++ code snippet that attempts to convert numbers to Roman numerals but contains syntax errors and logical issues.
  • Another participant notes that using a list of if-statements for numbers up to 10,000 could lead to a lengthy program, suggesting a need for a more efficient approach.
  • A participant expresses intent to try the code and share results, indicating a willingness to engage with the problem further.
  • Another participant points out that the current implementation correctly handles numbers 1 to 9 but suggests that the code should be expanded to accommodate larger numbers, including tens and hundreds.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to expand the program. There are differing views on how to efficiently handle the conversion for larger numbers, and the initial code has been identified as needing corrections.

Contextual Notes

The discussion highlights limitations in the current code, including syntax errors and incomplete handling of number ranges. There are also unresolved aspects regarding the best method for scaling the program to handle numbers beyond 9.

Who May Find This Useful

Individuals interested in C++ programming, particularly those looking to understand number conversion algorithms and improve their coding practices.

mulabisc
Messages
3
Reaction score
0
#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
If you're going to make a list of if-statements and you need to accept numbers up to 10,000 it's going to be a long program.
 
i wil try it n post it...thanks for the advice
 
Code:
else if(n >=1 && n <=3)

cout << "I";
This will print a I for numbers 1 to 3. You may want to check on it.

You are on the right track for 1 to 9.

Keep it up for other digits, tens, hundreds, etc.
 

Similar threads

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