1. This program goes into my functions more than once
  2. and i need a loop within the function instead.
  3. it is already formatted to run right away just
  4. copy and paste and you are on your way.
  5. Please post the answer to my question
  6.  
  7. #include <iostream>
  8. #include <iomanip>
  9. #include <cmath>
  10. #include <string>
  11. using namespace std;
  12. void romanrecorder_1();
  13. void romanrecorder_2();
  14. void romanprinter_1();
  15. void romanprinter_2();
  16. void operation();
  17. void roman_translator();
  18. void exitprogram();
  19. char opsign;
  20. char I,V,X,L,C,D,M;
  21. char letter_1;
  22. char letter_2;
  23. int a;
  24. int Ia;
  25. int b;
  26. int Vb;
  27. int c;
  28. int Xc;
  29. int d;
  30. int Ld;
  31. int e;
  32. int Ce;
  33. int f;
  34. int Df;
  35. int g;
  36. int Mg;
  37. int first_number;
  38. int second_number;
  39. int total;
  40. int romantotal;
  41. char roman_array[100];
  42. int main()
  43. {
  44. a=0;
  45. b=0;
  46. c=0;
  47. d=0;
  48. e=0;
  49. f=0;
  50. g=0;
  51. cout<<"Enter the first Roman Numeral followed by a dot(.): ";
  52. romanrecorder_1();
  53. return 0;
  54. }
  55. void romanrecorder_1()
  56. {
  57. cin>>letter_1;
  58. if (letter_1=='I')
  59. {
  60. a++;
  61. return romanrecorder_1();
  62. }
  63. else if (letter_1=='V')
  64. {
  65. b++;
  66. return romanrecorder_1();
  67. }
  68. else if (letter_1=='X')
  69. {
  70. c++;
  71. return romanrecorder_1();
  72. }
  73. else if (letter_1=='L')
  74. {
  75. d++;
  76. return romanrecorder_1();
  77. }
  78. else if (letter_1=='C')
  79. {
  80. e++;
  81. return romanrecorder_1();
  82. }
  83. else if (letter_1=='D')
  84. {
  85. f++;
  86. return romanrecorder_1();
  87. }
  88. else if (letter_1=='M'){
  89. g++;
  90. return romanrecorder_1();
  91. }
  92. else
  93. {
  94. romanprinter_1();
  95. }
  96. }
  97. void romanprinter_1()
  98. {
  99. Ia=1*a;
  100. Vb=5*b;
  101. Xc=10*c;
  102. Ld=50*d;
  103. Ce=100*e;
  104. Df=500*f;
  105. Mg=1000*g;
  106. first_number=Ia+Vb+Xc+Ld+Ce+Df+Mg;
  107. cout<<endl<<"The first Roman Numeral is "<<first_number;
  108. cout<<endl;
  109. a=0;
  110. b=0;
  111. c=0;
  112. d=0;
  113. e=0;
  114. f=0;
  115. g=0;
  116. cout<<endl<<"Enter the second Roman Numeral followed by a dot(.):";
  117. romanrecorder_2();
  118. }
  119. void romanrecorder_2()
  120. { cin>>letter_2;
  121. if (letter_2=='I')
  122. {
  123. a++;
  124. return romanrecorder_2();
  125. }
  126. else if (letter_2=='V')
  127. {
  128. b++;
  129. return romanrecorder_2();
  130. }
  131. else if (letter_2=='X')
  132. {
  133. c++;
  134. return romanrecorder_2();
  135. }
  136. else if (letter_2=='L')
  137. {
  138. d++;
  139. return romanrecorder_2();
  140. }
  141. else if (letter_2=='C')
  142. {
  143. e++;
  144. return romanrecorder_2();
  145. }
  146. else if (letter_2=='D')
  147. {
  148. f++;
  149. return romanrecorder_2();
  150. }
  151. else if (letter_2=='M'){
  152. g++;
  153. return romanrecorder_2();
  154. }
  155. else
  156. {
  157. romanprinter_2();
  158. }
  159. }
  160. void romanprinter_2()
  161. {
  162. Ia=1*a;
  163. Vb=5*b;
  164. Xc=10*c;
  165. Ld=50*d;
  166. Ce=100*e;
  167. Df=500*f;
  168. Mg=1000*g;
  169. second_number=Ia+Vb+Xc+Ld+Ce+Df+Mg;
  170. cout<<endl<<"The second number is "<<second_number;
  171. a=0;
  172. b=0;
  173. c=0;
  174. d=0;
  175. e=0;
  176. f=0;
  177. g=0;
  178. cout<<endl<<endl;
  179. cout<<"Enter the desired arithmetic operation: ";
  180. operation();
  181. }
  182. void operation()
  183. {
  184. cin >> opsign;
  185. if (opsign=='+')
  186. {
  187. total=first_number+second_number;
  188. cout<<endl<<"The sum of "<<first_number<<" and "<<second_number<<" is "<<total;
  189. }
  190. else if (opsign=='-')
  191. {
  192. if (first_number>second_number)
  193. {
  194. total=first_number-second_number;
  195. }
  196. else if (second_number>first_number)
  197. {
  198. total=second_number-first_number;
  199. }
  200. cout<<endl<<"The difference of "<<first_number<<" and "<<second_number<<" is "<<total;
  201. }
  202. else if (opsign=='*')
  203. {
  204. total=first_number*second_number;
  205. cout<<endl<<"The multiplication of "<<first_number<<" and "<<second_number<<" is "<<total;
  206. }
  207. else if (opsign=='/')
  208. {
  209. total=first_number/second_number;
  210. cout<<endl<<"The division of "<<first_number<<" and "<<second_number<<" is "<<total;
  211. }
  212. cout<<endl<<endl;
  213. cout<<"The roman numeral value of "<<total<<" is ";
  214. roman_translator();
  215. }
  216. void roman_translator()
  217. {
  218. romantotal=total+1;
  219. if (romantotal>0)
  220. {
  221. while (romantotal>total)
  222. {
  223. if ( total>=1000)
  224. {
  225. total=total-1000;
  226. cout<<"M";
  227. romantotal=total+1;
  228. return roman_translator();
  229. }
  230. else if (total>=500)
  231. {
  232. total=total-500;
  233. cout<<"D";
  234. romantotal=total+1;
  235. return roman_translator();
  236. }
  237. else if (total>=100)
  238. {
  239. total=total-100;
  240. cout<<"C";
  241. romantotal=total+1;
  242. return roman_translator();
  243. }
  244. else if (total>=50)
  245. {
  246. total=total-50;
  247. cout<<"L";
  248. romantotal=total+1;
  249. return roman_translator();
  250. }
  251. else if (total>=10)
  252. {
  253. total=total-10;
  254. cout<<"X";
  255. romantotal=total+1;
  256. return roman_translator();
  257. }
  258. else if (total>=5)
  259. {
  260. total=total-5;
  261. cout<<"V";
  262. romantotal=total+1;
  263. return roman_translator();
  264. }
  265. else if (total>1)
  266. {
  267. total=total-1;
  268. cout<<"I";
  269. romantotal=total+1;
  270. return roman_translator();
  271. }
  272. else if (total=1)
  273. {
  274. cout<<"I";
  275. total=total-3;
  276. cout<<endl<<endl<<endl<<endl;
  277. romantotal=total+1;
  278. return roman_translator();
  279. }
  280. else if (total<=0)
  281. {
  282. romantotal=-4;
  283. return roman_translator();
  284. }
  285. }
  286. cout<<endl<<endl;
  287. }
  288. if(romantotal=0)
  289. {
  290. cout<<endl<<endl<<endl;
  291. }
  292. }
  293.