Full Version: One Source Code,different Results
Dream.In.Code > Programming Tutorials > C++ Tutorials
born2c0de
This one's basically shows that MACROS when used in different compilers can give different results. This one teaches you to analyse C++ code and read it in Assembly and draw Conclusions about the results.
Really interesting if you read it completely...
It's Attached as an HTML File.
smartC

int main()
{
int num, i= 0, ii;
int currentDivide[7] = {1000, 500, 100, 50, 10, 5, 1};
int count[7];
char characters[7] = "'M', 'D', 'C', 'L', 'X', 'V', 'I'";
while((scanf("%c", characters)) != '\n'){
for(i = 0; i < 7; i++){
count[i] = num / currentDivide[i];
num %= currentDivide[i];

}
for(i = 0; i < 7; i++)
if(count[i] != 4 || i == 0)
for(ii = 0; ii < count[i]; ii++)
cout<<currentDivide[i];
else
cout<<currentDivide[i]<< currentDivide[i-1];
}



return 0;
}



Please, I want this codes to print the Numeric equivalent of the Roman Figures. I have a bit changed it to the switch/ case but special cases like VI/IV, XI/IX, LC/CL will not come up separetely. The are 6, 11, and 150 respectively. See the basic case condition


switch(cha){

case 'M':
sum += 1000;
cout<<sum;
:::
:::
:::
case 'I':
sum += 1;
cout<<sum;
}

This thus gives VI/IV as 6 instead of 6/4. Same as IX/XI giving 11 instead of 9/11. Can you help for the special cases like IV/VI, XI/IX, LX/XL MX/XM etc?
My email address is smart_ikhu@hotmail.comī
Thanks.




This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.