Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google Log In with Steam Sign In
  • Create Account

Multiple Tables C++

- - - - - programming c++

  • Please log in to reply
14 replies to this topic

#1
OFFLINE   Corey

Corey

    L7: Teacher

  • Staff
  • 1496 posts
  • Admin:18
  • Server:Silent
  • COD4 GUID:c0f2e4c2
Contributor
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




Posted Image

Posted Image


#2
OFFLINE   rolf

rolf

    L6: Expert

  • +++Platinum VIP
  • 827 posts
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;
}


#3
OFFLINE   Corey

Corey

    L7: Teacher

  • Staff
  • 1496 posts
  • Admin:18
  • Server:Silent
  • COD4 GUID:c0f2e4c2
Contributor
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

Posted Image


#4
OFFLINE   rolf

rolf

    L6: Expert

  • +++Platinum VIP
  • 827 posts
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 :P
	  // Basicly, only get the values based on year y and startvalue j and print those
	}
  }
  cout<<endl;
}


#5
OFFLINE   Corey

Corey

    L7: Teacher

  • Staff
  • 1496 posts
  • Admin:18
  • Server:Silent
  • COD4 GUID:c0f2e4c2
Contributor
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 :)

Posted Image


#6
OFFLINE   rolf

rolf

    L6: Expert

  • +++Platinum VIP
  • 827 posts
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)

#7
OFFLINE   PiNoY

PiNoY

    L5: Journeyman

  • ++Gold VIP
  • 688 posts
Contributor
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

#8
OFFLINE   PiNoY

PiNoY

    L5: Journeyman

  • ++Gold VIP
  • 688 posts
Contributor
attached is the output

Attached File  code.jpg   89.77K   15 downloads

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!

#9
OFFLINE   Corey

Corey

    L7: Teacher

  • Staff
  • 1496 posts
  • Admin:18
  • Server:Silent
  • COD4 GUID:c0f2e4c2
Contributor
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.

Posted Image


#10
OFFLINE   rolf

rolf

    L6: Expert

  • +++Platinum VIP
  • 827 posts
Ask for help earlier next time then :P

#11
OFFLINE   PiNoY

PiNoY

    L5: Journeyman

  • ++Gold VIP
  • 688 posts
Contributor

View PostCorey, on 08 February 2012 - 11:05 AM, said:

lol your very first c++ program? :P

There was no c++ in my place 20 years ago. No problem, thank you too

#12
OFFLINE   rolf

rolf

    L6: Expert

  • +++Platinum VIP
  • 827 posts
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.

#13
OFFLINE   PiNoY

PiNoY

    L5: Journeyman

  • ++Gold VIP
  • 688 posts
Contributor
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).

#14
OFFLINE   Corey

Corey

    L7: Teacher

  • Staff
  • 1496 posts
  • Admin:18
  • Server:Silent
  • COD4 GUID:c0f2e4c2
Contributor

View Postrolf, on 08 February 2012 - 11:49 AM, said:

Ask for help earlier next time then :P

yeah procrastination sucks hehe

Posted Image


#15
OFFLINE   asp

asp

    L3: Novice

  • Regular User
  • 54 posts
Damn, you really need to make your code easier to read :D





Also tagged with programming, c++

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users