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

In summary, the code prompts the user to enter an integer number and checks for specific conditions to determine the Roman numeral equivalent. It covers numbers 1 to 9, but would require a lot more code for numbers up to 10,000.
  • #1
mulabisc
3
0
#include <iostream>
using namespace std;

int main()
{

int n;
n >=1;

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

if(n == 9)

cout << "IX";

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

cout << "V";

else if (n == 4)

cout << "IV";


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

cout << "I";




return 0;
}
 
Technology news on Phys.org
  • #2
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.
 
  • #3
i wil try it n post it...thanks for the advice
 
  • #4
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.
 

What is the purpose of this C++ program?

The purpose of this C++ program is to convert numbers from 1 to 1000 into their written form. This can be useful for tasks such as writing checks or filling out forms that require written numbers.

What is the input for this program?

The input for this program is a number between 1 and 1000 entered by the user.

What output can I expect from this program?

The output of this program will be the written form of the input number. For example, if the input is 123, the output will be "one hundred twenty-three".

Are there any limitations to this program?

Yes, this program can only convert numbers between 1 and 1000. Any numbers outside of this range will result in an error message.

How can I use this program in my own code?

You can use this program by calling the convertToWords() function and passing in a number as the argument. The function will then return the written form of the input number as a string, which you can use in your own code as needed.

Similar threads

  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
Replies
22
Views
2K
  • Programming and Computer Science
Replies
12
Views
1K
  • Programming and Computer Science
2
Replies
39
Views
3K
  • Programming and Computer Science
Replies
5
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
  • Programming and Computer Science
Replies
6
Views
8K
  • Programming and Computer Science
3
Replies
89
Views
4K
  • Programming and Computer Science
Replies
1
Views
983
  • Programming and Computer Science
Replies
4
Views
777
Back
Top