Page 1 of 1

One Source Code,different Results MACROS v/s FUNCTIONS v/s COMPILERS Rate Topic: ***-- 3 Votes

#1 born2c0de  Icon User is offline

  • printf("I'm a %XR",195936478);
  • member icon

Reputation: 180
  • View blog
  • Posts: 4,667
  • Joined: 26-November 04

Post icon  Posted 13 January 2005 - 09:57 AM

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.

Attached File(s)


Is This A Good Question/Topic? 0
  • +

Replies To: One Source Code,different Results

#2 smartC  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 25-July 07

Posted 27 July 2007 - 05:29 AM

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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1