I need some help with a problem involving arrays.

It's a 3 column array calculating interest one year to the next.

Page 1 of 1

5 Replies - 839 Views - Last Post: 08 April 2008 - 08:53 PM Rate Topic: -----

#1 Chevrolet Fanatic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 28-February 08

I need some help with a problem involving arrays.

Post icon  Posted 06 April 2008 - 09:26 PM

I've looked over this problem for a while and have came up with basically just the start of the project. I haven't been able to figure out how to insert the year 1625 and add a year each time. Or insert the amount of 24 dollar starting amount of money and multiply by the given 3.75 percent interest to get the final total for one year, and then do it again to get the following years total. The description of the problem confused me for one thing. I automatically thought I should do it using arrays because that looked like it was the best way. I've attempted doing a couple of different things trying to calculate the year, interest and total but nothing has worked out the way it's supposed to and I really just need some help or input to know where I'm going with it, or if I'm totally starting out the wrong way to do it.



Here is the problem:

In 1624, Peter Minuit bought Manhattan island for the amount of $24.00. Had the locals invested that money in the bank at 3.75% interest, what would their investment be worth today? Make the output of this program look like this:

Manhattan Island Interest Calculation___________________Page 1

Year____________Interest Earned_______________Total
1625____________xxx.xx______________________xxx.xx
1626____________xxx.xx______________________xxx.xx
1627____________xxx.xx______________________xxx.xx
1628____________xxx.xx______________________xxx.xx
1629____________xxx.xx______________________xxx.xx
1630____________xxx.xx______________________xxx.xx

and so on. After every five years of output, skip a blank line. After 15 years of output, display a message that says, "Press a key to continue" and then clear the screen and start displaying. Make sure you count the page numbers. Also, on the line when the total first goes over 1000000, display asterisks (***) beside the year.



Here is my code so far:

#include <iostream>
using namespace std;

void year_array(int [],int);
void interest_array(int [], int);
void total_array(int[], int);
void print_array(int [], int [], int[], int);

int main()
{
	int year[15];
	int interest[15];
	int total[15];
	int n=15;
	
	year_array(year,n);
	interest_array(interest,n);
	total_array(total,n);
	print_array(year,interest,total,n);

return 0;
}

void year_array(int year[],int n)
{
	for(int x=0; x<0; x++)
	{
		year[x];
	}
}


void interest_array(int interest[],int n)
{
	for(int y=0; y<n; y++)
	{
		interest[y];
	}
}

void total_array(int total[],int n)
{
	for(int z=0; z<n; z++)
	{
		total[z];
	}
}

void print_array(int year[], int interest[], int total[], int n)
{	
	cout<<"Year"<<"\t"<<"Interest Earned"<<"\t"<<"Total"<<"\n";
	for(int a=0, b=0, c=0; a<n; a++, b++, c++)
	{
		cout<<year[a]<<"\t";
		cout<<interest[b]<<"\t";
		cout<<total[c]<<"\n";
	}
}




I was also really confused on the second part of the problem that says to skip a line every five years, and keep going until their is 15 years. Then clear the screen and continue displaying for the next 15 years. I'm guessing every 15 years when you clear the screen it counts for a page? The page counter and asterisks have me kind of confused as well how to do them, the asterisks displaying beside the year that the total reaches over 1000000 especially.

I've worked with arrays before and also have looked through a lot of tutorials and threads trying to figure out a way to do the first part and couple it with the second part but I think I'm having a brain overload and am over thinking it or something. This is the hardest project I've done and is a lot harder than anything else I have ever tried so it's really giving me fits.

I would greatly appreciate it if someone else would take a look at it and let me know what their take on it is or what they think is wanted from the problem. I've just come to a mental brick wall and can't figure out where to go from here.

Any help would be greatly appreciated.

Thanks!

This post has been edited by Chevrolet Fanatic: 06 April 2008 - 09:55 PM


Is This A Good Question/Topic? 0
  • +

Replies To: I need some help with a problem involving arrays.

#2 no2pencil  Icon User is offline

  • Toubabo Koomi
  • member icon

Reputation: 5182
  • View blog
  • Posts: 26,886
  • Joined: 10-May 07

Re: I need some help with a problem involving arrays.

Posted 06 April 2008 - 09:41 PM

Quote

I was also really confused on the second part of the problem that says to skip a line every five years, and keep going until their is 15 years. Then clear the screen and continue displaying for the next 15 years. I'm guessing every 15 years when you clear the screen it counts for a page? The page counter and asterisks have me kind of confused as well how to do them, the asterisks displaying beside the year that the total reaches over 1000000 especially.


I think something like this is in answer to this question...

#include <stdio.h>

int main(void) {
  int years=0;

  while(years<15) {
    printf("%i\n",years+1980);
    if(years % 5 == 0) {
      printf("\n");
    }
    years++;
  }
  cls();  // Assuming that you are on a Windows machine

  return 0;
}



The output is something like :

Quote

>$./years
1980

1981
1982
1983
1984
1985

1986
1987
1988
1989
1990

1991
1992
1993
1994

Was This Post Helpful? 0
  • +
  • -

#3 Chevrolet Fanatic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 28-February 08

Re: I need some help with a problem involving arrays.

Posted 07 April 2008 - 11:40 AM

Oh, ok, I see now about that. Then when I clear the screen each time I can just make a counter to count the pages each time the screen is cleared can't I?

Whenever I try to calculate interest earned and total I'm still not getting anything. I've tried defining an integer and then doing the calculation making its answer equal to that integer. I then make the integer equal to the corresponding array. I also tried doing it like the year array but I just ended up confusing my own self.

I'm not sure, I probably am doing the math wrong in it. I can't figure out how to make it start out with 3.75% interest from $24 dollars which will be $0.90 then show the total for that first line which will be $24.90, and then on the next line take that total and multiply it by .0375 again to get the interest earned from $24.90(the total from the 1st line) which will be $0.93 and then add it to the total to get the new total for the second line which would be $25.83.

Then continue doing that until the total reaches $1000000, which then I need to put asterisks (***) beside of that year that it reaches it.

This is what I tried but it's all messed up I know.

void interest_array(int interest[],int n)
{
	 int InterestEarned=0;  
   
	 while(InterestEarned<15) 
	{  
	 printf("%i\n",InterestEarned+24*.0375);  
		 if(InterestEarned % 5 == 0) 
		{  
			 printf("\n");  
		 }  
	 InterestEarned++;  
	 }  
}


Thanks

This post has been edited by Chevrolet Fanatic: 07 April 2008 - 11:42 AM

Was This Post Helpful? 0
  • +
  • -

#4 Chevrolet Fanatic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 28-February 08

Re: I need some help with a problem involving arrays.

Posted 08 April 2008 - 06:33 PM

I'm still not getting it to print out right. I know I'm doing it wrong. I tried doing it like shown and also tried it another way using for loops, bust still cannot get it to compile correctly and I do not know what I am doing wrong.

void year_array(int year[],int n)
{
  int years=0;

  while(years<15) 
	{
		printf("%i\n",years+1625);
			if(years % 5 == 0) 
			{
				printf("\n");
			}
		years++ = year[];
	}
}


I've looked online everywhere but I cannot find any tutorials on doing mathematical calculations inside of an array. Even just taking a year like so and starting out at 1625 and then adding 1 year each line.

Or how to start out with $24 as your total and add to it the money made from 3.75% interest each year.

I'm still just really confused and could extremely use some help if anyone can help me out please.
Was This Post Helpful? 0
  • +
  • -

#5 baavgai  Icon User is online

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: I need some help with a problem involving arrays.

Posted 08 April 2008 - 07:27 PM

First, NO ARRAYS! They're not required, or optimal, and they're confusing you.

Here's a kick to get you going. This is basically the answer. You should be able to figure out a page break, a page increment, etc, from here.

#include <iostream>
using namespace std;

int main(void) {
	const double interestRate = 0.0375;
	int currentYear = 1624;
	double total = 24;
	int pageNo = 1;
	int fiveBreak = 1;

	while(currentYear<2009) { 
		currentYear++;
		double interest = ((int)(total * interestRate * 100.0))/100.0;
		total += interest;
		cout << currentYear 
			<< "\t" << interest
			<< "\t" << total
			<< endl;
		if (fiveBreak++ == 5) {
			fiveBreak = 1;
			cout << endl;
		}
	}
}



I can't in good conscience offer more than this. Good luck.
Was This Post Helpful? 0
  • +
  • -

#6 Chevrolet Fanatic  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 27
  • Joined: 28-February 08

Re: I need some help with a problem involving arrays.

Posted 08 April 2008 - 08:53 PM

Alright, I'll look at that and see if I can figure it out now.

Thank you very much for the help. I appreciate it greatly.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1