Monday, May 24, 2010

How do i condience this c++ code to make it less crowded?

for ( int year = 2007; year %26lt;= 2037; year++ )


{


amount = amount * rate + principal;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


principal = principal + 200;


out %26lt;%26lt; setw ( 4 ) %26lt;%26lt; year %26lt;%26lt; setw ( 34 ) %26lt;%26lt; amount %26lt;%26lt; endl;


}





out.close();


return 0;


}

How do i condience this c++ code to make it less crowded?
It seems like perhaps something is missing here anyway. You calculate "amount" once and then don't do anything with it until you print it out in the end. Is amount supposed to be somewhere in that equation? I get the impression you are trying to do compound interest. Anyway, if that is the case, I would recommend a for loop:





for(int i = 1; i%26lt;=12; i++)


{


// Do your equation


}
Reply:Would you mind telling me what you're trying to achieve there. Because if its SI/CI you're trying to do there, I just cant figure it out
Reply:for ( int year = 2007; year %26lt;= 2037; year++ )


{


amount = amount * rate + principal;


principal+=200*12;


out%26lt;%26lt;setw(4)%26lt;%26lt;year%26lt;%26lt;setw(34)%26lt;%26lt;amount%26lt;,...


}





out.close();


return 0;


}

online florists

No comments:

Post a Comment