C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old September 29th, 2005, 06:38 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Another For(loop Question = 0; geo.brain <NULL;loopQuestion++)

Ok I'm tired of asking these simple question probably as tired as you are answering them. I am having trouble with a question, and I don't know why this chapter of this book has stumped me so bad, it seems as if I have done harder stuff than this. So, here's the question.
Quote:
Daphne invest $100 at 10% simple interest. That is, every year, the investment earns 10% of the original investment, or 10$ each and every year:

interest = 0.10 * original balance

at the same time, Cleo invests $100 at 5% compound interest. That is, interest is 5% of the current balance, including previous additions of interest:

interest = 0.05% * current balance

Cleo earns 5% of $100 the first year, giving her $105. The next year she earns 5% of $105, or $5.25 and so on. Write a program that finds how many years it takes for the value of Cleo's investment to exceed the value of Daphne's investment and then displays the value of both investment at that time.


Now you can also use a while loop along with for loops as well. I have done this in several ways and I am still having trouble getting Cleo's current balance to be accurate. I have used a struct to put all there information in and then create an array of the struct to separate them, but this doesn't seem to work very good once its time to calculate the problem. I'm going to post some of my results after a bit, but I got to re-write them because I keep erasing and starting over.

I can do the math on a stinkin calculator but I cant seem to figure this question out for the life of me. The sad thing is, is that you guys will probably solve it in a matter of minutes.

A side question: Can a person with mediocre math skills still do well in programming?

Reply With Quote
  #2  
Old September 29th, 2005, 07:33 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
What I have so far!!

Code:
#include <cstdlib>
#include <iostream>
#include <string>

using namespace std;
struct User
{
    string name;
    float origB;//original balance
    float currB;//current balance
    float yTd;//interest over a year
    float inter;//interest percent
    float BooYaa;//sum 
};
User U[2]={
     {"Daphne",100,0,0,0.10,0},
     {"Cleo",100,0,0,0.05,0}
     };

int main(void)
{
    int i, j = 0;
    for(i = 0; i < 2; i++)
    {
          U[i].currB = U[i].origB * U[i].inter + U[i].origB;//Both
          U[0].yTd = U[0].inter * U[0].origB;//Daphne
          U[1].yTd = U[1].inter * U[1].currB;//Cleo
          U[0].BooYaa = U[0].yTd + U[0].origB;//Daphne
          U[1].BooYaa = U[1].yTd + U[1].currB;//Cleo
          cout<<U[i].name<<" invested : "<<U[i].origB<<endl;
          cout<<" Two years : "<<U[i].BooYaa<<endl;
           }
    
    system("PAUSE");
    return 0;
}

When I try to enter a j into the for loop it crashes. The j loop I tried looks some like this
Code:
for (i = 0, j = U[1].BooYaa; i < 2, j > U[0].BooYaa; i++, j++)
then I changed the statement
cout<<" Two Years : "<<U[i].BooYaa<<endl;
to
cout<<" Two Years : "<<U[j].BooYaa<<endl;

Now am I horribly off tract or am I still in the ball park!! The reason why I am concentrating on the for loop is, because that is an area that I am having the most trouble understanding right now. I understand the do and while perfectly fine just the for is really bothering me at the moment.

Reply With Quote
  #3  
Old September 30th, 2005, 02:43 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Quote:
Originally Posted by Geo.Garnett
A side question: Can a person with mediocre math skills still do well in programming?


He can, but with difficulty.

Like you said, you're looking at this from the wrong side. The trick is to reduce it to simple mathematics.

Daphne's balance after x years will be:
100 + (10 * x)
whereas Cleo's balance will be:
100 * 1.05^x

taking this and putting it in a program, we get:
cpp Code:
Original - cpp Code
  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.     // declarations
  7.     float daphne = 100.0, cleo = 100.0;
  8.     int years;
  9.  
  10.     // run while Cleo's balance is smaller or equal to Daphne's
  11.     for(years = 0; cleo <= daphne; years++)
  12.     {
  13.         daphne = 100 + 10 * years;
  14.         cleo = 100 * pow(1.05, years);
  15.         // uncomment the following line if you want to see the intermediate results
  16.         // printf("after %d years, Cleo's balance is %.2f, and Daphne's balance is %.2f\n", years, cleo, daphne);
  17.        
  18.     }
  19.  
  20.     // output data
  21.     printf("after %d years, Cleo's balance is %.2f, and Daphne's balance is %.2f\n", years, cleo, daphne);
  22.  
  23.     // exit
  24.     return 0;
  25. }


Remember, simpler is always better :-)
__________________
This is my code. Is it not nifty?

"The biggest problem encountered while trying to design a system that was completely foolproof, was, that people tended to underestimate the ingenuity of complete fools."
---Douglas Adams


Join the Itsacon fanclub!    
Zero Tolerance: Spammers banned so far: 280

Reply With Quote
  #4  
Old September 30th, 2005, 03:06 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
TY Itsacon

You know I think the main thing is that I don't have a complete understanding of all the syntax used in C/C++ yet or I probably might have figured that one out on my own. But in all the books I have read they have never touched on the #include<math.h> library functions, so you can guess that all the little tricks I have not learned yet.

My math skills compared to another normal person I would say is above average but to a programmers math skills, well, then there only mediocre. But there getting better. I use to be in the construction business, and was pretty high up, and we used math quite a bit, but programming is definitely on a different level.

I want to thank you again Itsacon for helping me out with this problem. Your effort is greatly appreciated I assure you

OH wait one question, how did you come up with 1.05 for Cleo. I dont understand that part. Do you do the math out and then calculate the percent it should be

Reply With Quote
  #5  
Old September 30th, 2005, 03:09 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
You're welcome.

I suggest you go over the library reference on www.cplusplus.com if you have the time. They have a comprehensive list of all functions in all the different C libraries, with explanation, syntax, etc.

Reply With Quote
  #6  
Old September 30th, 2005, 03:17 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Ok, thanks for that link Itsacon, I will definitely go over that. I read anything I can get my hands on, and that's probably my problem. I read so much about it and give myself little time to practice what I've read, and end up having to go over it again, much like I'm doing right now. I have read this portion almost a month ago, but I learned now, that with programming you need to be working right along with your book or when you go back to the exercises you'll be lost

By the way I made an addition to my last post, lol probably while you were answering it. Its a simple question I'm sure but its pretty late here and what little brain matter I had going for me, is almost non existent now.

Reply With Quote
  #7  
Old September 30th, 2005, 03:34 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
5 percent equals five hundreths of something, or 0.05
To add 5 percent to something, you can say:
something = something + something * 0.05
but the shorter version is to add 1 to 0.05, getting 1.05

something = something * 1.05

Or the full mathematical proof (now using x, as it's shorter )

x = x + x * 0.05
x = x * 1 + x * 0.05
x = x * (1 + 0.05)
x = x * 1.05


Reply With Quote
  #8  
Old September 30th, 2005, 03:41 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
LMBO right now. you were right about keeping it simple. I think I am over thinking everything thats for sure, and not sticking to the basics. I understand math but its like I try and create a new type a math once I start programming. lol I think , Thanks for the better explanation, and hey by the way, what time is it there in the Netherlands? Just wondering, its 3:30 here.

Reply With Quote
  #9  
Old September 30th, 2005, 03:43 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
9:45 am, just started at work

Reply With Quote
  #10  
Old September 30th, 2005, 03:46 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Cool, well, I'll quit on that note, and thanks for your help again. I guess it would help if I slept for a while, that is probably my biggest problem, lol.

Reply With Quote
  #11  
Old September 30th, 2005, 03:47 AM
Itsacon's Avatar
Itsacon Itsacon is offline
Command Line Warrior
Click here for more information
 
Join Date: Aug 2004
Location: Sector ZZ9 Plural Z Alpha
Posts: 997 Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)Itsacon User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2Folding Points: 909006 Folding Title: Super Ultimate Folder - Level 2
Time spent in forums: 6 Days 14 h 26 m 27 sec
Reputation Power: 5
Send a message via ICQ to Itsacon
Good night...

Reply With Quote
  #12  
Old September 30th, 2005, 03:51 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 4
Send a message via AIM to Geo.Garnett
Nite!

Reply With Quote