Jump to content

Multiple Tables C++


Corey

Recommended Posts

I am supposed to make a table based on interest rates on loans or something like that :P 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

 

 

 

 

aaaaaazv.png

Link to comment
Share on other sites

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;
}

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Ah, no. That 'do your magic' was indeed slightly wrong, but you have to read what you should do with the code itself ofcourse :P

 

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;
}

  • Like 1
Link to comment
Share on other sites

The teacher didnt want us to use arrays :( just loops. worst problem i ever had :P

 

i <3 copy paste lol. thanks for the help rolf ill see if i can figure it out :)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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. :P

Link to comment
Share on other sites

lol your very first c++ program? :P

 

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.

Link to comment
Share on other sites

C++ is 28 years old :P However, if you have experience with C (and OOP, not for this exercise, but both are older), C++ is quite easy to learn.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

  • 2 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.