Help roman numeral program multi-character character constant

Here is my code i want to get rid of the warnings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <fstream>
#include <string>
using namespace std;

int main() {

 int r=1223;
 int m;
 int d;
 int c;
 int lx;
 int l;
 int xl;
 int x;
 int vi;
 int v;
 int iv;
 int i;

  while (r >= 1000) {
      //int m;
     m = r/1000;
     r = r - m *1000;
   }
  while (r >= 500) {
      //int d;
     d = r/500;
     r = r - d *500;
   }
  while (r >= 100) {
      //int c;
     c = r/100;
     r = r - c *100;
   }
  while (r >= 60) {
      //int lx;
     lx = r/60;
     r = r - lx *60;
   }
  while (r >= 50) {
      //int l;
     l = r/50;
     r = r - l *50;
   }
  while (r >= 40) {
      //int xl;
     xl = r/40;
     r = r - xl *40;
   }
  while (r >= 10) {
      //int x;
     x = r/10;
     r = r - x *10;
   }
  while (r >= 6) {
      //int vi;
     vi = r/6;
     r = r - vi *6;
   }
  while (r >= 5) {
      //int v;
     v = r/5;
     r = r - v *5;
   }
  while (r >= 4) {
      //int iv;
     iv = r/4;
     r = r - iv *4;
   }
  while (r >= 1) {
      //int i;
     i = r/1;
     r = r - i *1;
   }

  if (r>0){
	  cout << "error call the programmer we didn't get to zero";
  }
  else {
// I tried this but i still get the same error
//      std::cout << std::string(m, 'M');
//	  std::cout << std::string(d, 'D');
//	  std::cout << std::string(c, 'C');
//	  std::cout << std::string(lx, 'LX');
//	  std::cout << std::string(xl, 'XL');
//	  std::cout << std::string(x, 'X');
//	  std::cout << std::string(vi, 'VI');
//	  std::cout << std::string(v, 'V');
//	  std::cout << std::string(iv, 'IV');
//	  std::cout << std::string(i, 'I');
//	  cout << "\n";
//
	    string thosand_pl(m, 'M');
	    string fivehun_pl(d, 'D');
	    string onehun_pl(c, 'C');
	    string sixty_pl(lx, 'LX'); //this line i can't make it work
	    string fifty_pl(l, 'L');
	    cout << thosand_pl << fivehun_pl << onehun_pl << sixty_pl << fifty_pl;
  }
  return 0;
}


multi-character character constant line 97
Last edited on
I believe it's possible to fix with something like:
1
2
3
string sixty_pl;
while (lx--)
  sixty_pl += "LX";

But it won't work anyway. You don't initialize variables and you can get very strange results or an infinite loop. I believe you should write and test a smaller program at first - for example converting numbers from 1 to 3. Then from 1 to 5, etc.
Last edited on
sorry i am a bit of a beginner, but i don't understand what you mean please explain
I'm a beginner too :). But I tried your program with my fix and get an infinite loop. After using debugger I saw that variable of lx had the value like -83934300. It means it didn't get any value in one of your "while" loop.

And as a beginner (in C++) I would try to get a simpler but working prototype - like converting from 1 to 3. And then I'd think about further development.
Topic archived. No new replies allowed.