Corey Posted February 1, 2012 Posted February 1, 2012 I am supposed to make a table based on interest rates on loans or something like that I finally after days managed to get the table to work, but there is one more step i have to do. The cmd prompt winodw will only allow small tables . So i am supposed to have it make different tables. Like the screenshot of the one i have working the collums only go from 8.00 - 9.00 in increments of .25. I am supposed to get all the way up to 16.00. So after my table of 8-9 is printed out on the screen it is supposed to print out another table from 9.25 -10 . then another table from 10.25- 11 and so on. I tried googling but i dont even know how to word the question properly http://nopaste.info/f04ff361f6.html - code Quote
rolf Posted February 1, 2012 Posted February 1, 2012 You mean below eachother? int maxColumns = 5; int maxValues = int((inputEnd-inputStart+increment)/increment); // with +increment, otherwise you won't get the last value for(int i=0;i<=maxValues;i += maxcolumns) { // for each block of at most maxColums with do ... float start = inputStart + increment*i; // start for following output block float end = min(inputStart+increment*(i+1), inputEnd) // end for output block, which is either max value or the max you want to print for(float j=start;j<=end;j+=increment) { // do the magic you already have } cout<<endl; } Quote
Corey Posted February 1, 2012 Author Posted February 1, 2012 yeah below each other. int maxColumns = 5; int maxValues = int((interestRange2-interestRange1+Increment)/Increment); // with +increment, otherwise you won't get the last value for(int i=0;i<=maxValues;i += maxColumns) { // for each block of at most maxColums with do ... float start = interestRange1 + Increment*i; // start for following output block float end = min(interestRange1+Increment*(i+1), interestRange2); // end for output block, which is either max value or the max you want to print for(float j = start;j<=end;j +=Increment) { for (int i = yearRange1; i <= yearRange2; i++) { cout<<"Year "<<i<<"\t "; outfile<<"Year "<<i<<"\t "; for(double j = interestRange1; j <= interestRange2;j++) { cout<<fixed<<showpoint<<setprecision(5)<<paymentfac(interestRange1,yearRange1)<<"\t"; outfile<<fixed<<showpoint<<setprecision(5)<<paymentfac(interestRange1,yearRange1)<<"\t"; j = j - 0.75; interestRange1 = interestRange1 + Increment; while (interestRange1 > interestRange2 && yearRange1 < yearRange2) { interestRange1 = 8.00; yearRange1 = yearRange1 + 1; } } cout<<endl; outfile<<endl; } // do the magic you already have } } is this what you meant for it to look like? i replaced inputStart with the interestRange1 where the interest will start(8.00) and inputEnd with interestRange2 where the interest rate will end (16.00) what i pasted did not make the tables print out properly :X Quote
rolf Posted February 1, 2012 Posted February 1, 2012 Ah, no. That 'do your magic' was indeed slightly wrong, but you have to read what you should do with the code itself ofcourse In my second for loop I let you iterate over all things, but instead you should iterate over all years and then over all points. Hence, int maxColumns = 5; int maxValues = int((inputEnd-inputStart+increment)/increment); // with +increment, otherwise you won't get the last value for(int i=0;i<=maxValues;i += maxcolumns) { // for each block of at most maxColums with do ... float start = inputStart + increment*i; // start for following output block float end = min(inputStart+increment*(i+1), inputEnd) // end for output block, which is either max value or the max you want to print for(int y=yearStart;y<yearEnd;y++) { for(float j=start;j<=end;j+=increment) { // do the magic you already have, but no simple copy-paste // Basicly, only get the values based on year y and startvalue j and print those } } cout<<endl; } 1 Quote
Corey Posted February 1, 2012 Author Posted February 1, 2012 The teacher didnt want us to use arrays just loops. worst problem i ever had i <3 copy paste lol. thanks for the help rolf ill see if i can figure it out Quote
rolf Posted February 1, 2012 Posted February 1, 2012 Yeah, instead of arrays you can use your paymentfac() That being said, I would getting slapped to death by more than one people if I use loops instead of array's, the latter one are way more efficient (and in real life, efficiency counts) Quote
PiNoY Posted February 2, 2012 Posted February 2, 2012 I think loop can do the job. Create a variable that would hold the value when checking if YEAR is divisible by 20 with 0 quotient. You can use MOD operator on that. If results of MOD operation is zero, then the value of YEAR is divisible by 20 then. For example the loop causes YEAR to reach the value of 20. Then use MOD, YEAR (20) mod 20 = 0 . This is a trigger or signal that would give you a hint that a new LINE is needed to draw the HEADER TITLES (Monthly Payment Factors used in Comput etc etc) then repeat the loop cycle again without losing variable values of I, J, fixed and the rest of variable. EDIT: I was referring to 20 coz it was specified as 20. But you can refer to it as the variable holding the maximum year entered by user - yearRange2. Then follow thru with MOD operation. The above works in my head. Quote
PiNoY Posted February 8, 2012 Posted February 8, 2012 attached is the output and here's the modified version: http://nopaste.info/3500a67b45.html goodluck! ps: hope that works, sorry its my very first c++ program, i just learned things from your code. thank you! Quote
Corey Posted February 8, 2012 Author Posted February 8, 2012 lol your very first c++ program? Well for your first program that is pretty impressive Unfortunately i turned it in last week without getting the multiple tables, but its all good. I appreciate you trying and at least I have something to look at for next time. Quote
PiNoY Posted February 8, 2012 Posted February 8, 2012 lol your very first c++ program? There was no c++ in my place 20 years ago. No problem, thank you too Quote
rolf Posted February 8, 2012 Posted February 8, 2012 C++ is 28 years old However, if you have experience with C (and OOP, not for this exercise, but both are older), C++ is quite easy to learn. Quote
PiNoY Posted February 8, 2012 Posted February 8, 2012 i think so. i got familiar with pascal that time. its not my kind of work but hey, what do they use to edit those source codes? idk but i was using a text editor and compiling the code using gcc++ compiler (am not using windows btw). Quote
Corey Posted February 8, 2012 Author Posted February 8, 2012 Ask for help earlier next time then yeah procrastination sucks hehe Quote
asp Posted April 26, 2012 Posted April 26, 2012 Damn, you really need to make your code easier to read Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.