Question: I had to copy and paste because chug doesn't allow me to upload my source file, it only allows images, but I believe the problem

I had to copy and paste because chug doesn't allow me to upload my source file, it only allows images, but I believe the problem is in the "for" loop in the after function and in the main when trying to output the roman numeral. Because in. the solution it says to just put "for (j=0;j" in both the main and in the after function, which is a syntax error.

#include using namespace std;

char rom[10000]; int i = 0; long int decimal;

void before (char c1, char c2) { rom [i++] = c1; rom [i++] = c2; }

void after (char c, int n) { int j; for (j=0; j

}

int above_thousand (int decimal) { after('M', decimal/1000); decimal = decimal - (decimal/1000) * 1000; return decimal; }

int above_fivehundred(int decimal) { if (decimal < (500+4*100)) { after('D', decimal/500); decimal = decimal - (decimal / 500) * 500; } else { before('C' , 'M'); decimal = decimal - (1000-100);

} return decimal; } int above_hundred(int decimal) { if (decimal < (100 + 3 * 100)) { after('C', decimal/100); decimal = decimal - (decimal/100) * 100; } else { before ('L', 'D'); decimal = decimal - (500-100);

} return decimal; }

int below_hundred(int decimal) { if (decimal >= 50) { if (decimal < (50+4*10)) { after ('L' , decimal / 50); decimal = decimal - (decimal/50) * 50; } else { before ('X', 'C'); decimal = decimal - (100-10);

} } else if(decimal >= 10) { if (decimal <(10 + 3 * 10)) { after ('X', decimal / 10); decimal = decimal - (decimal / 10) * 10; } else { before ('X', 'L'); decimal = decimal - (50 - 10); } } else if (decimal >= 5) { if (decimal < (5 + 4 *1)) { after ('V', decimal/5); decimal = decimal - (decimal/5) * 5; } else { before ('I', 'X'); decimal = decimal - (10 - 1); } } else if (decimal >= 1) { if (decimal < 4) { after ('I' , decimal/1); decimal = decimal - (decimal/1) *1;

} else { before ('I' , 'V'); decimal = decimal - (5-1); } } return decimal; } int main () { int j; cout << "Enter the number you would like to convert to roman number:"; cin >> decimal; while (decimal != 0) { if (decimal >= 1000) { decimal = above_thousand(decimal); } else if (decimal >= 500) { decimal = above_fivehundred(decimal);

} else if (decimal >=100) { decimal = above_hundred(decimal);

} else { decimal = below_hundred(decimal); }

cout << "Equivalent Roman Numeral is: ";

for (j=0; j < decimal; j++) { cout << rom[j]; }

} return 0; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!