| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
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:
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? ![]() |
|
#2
|
||||
|
||||
|
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. ![]() |
|
#3
|
||||||
|
||||||
|
Quote:
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:
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
![]() |
|
#4
|
||||
|
||||
|
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 ![]() |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
||||
|
||||
|
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. ![]() |
|
#7
|
||||
|
||||
|
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 ![]() |
|
#8
|
||||
|
||||
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. ![]() |
|
#9
|
||||
|
||||
|
9:45 am, just started at work
![]() |
|
#10
|
||||
|
||||
|
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.
|
|
#11
|
||||
|
||||
|
Good night...
|
|
#12
|
||||
|
||||
Nite! |