-
July 14th, 2011, 03:29 PM
#16
Re: Loop Problem
Originally Posted by josh26757
Interesting,
If you do not mind give me an example of using integer math. I may be misunderstanding you but how do I get cents with an integer( I am such a noob).
How many cents are in a dollar? 1 is 1 cent. 100 is 100 cents, or 1 dollar. 1000 is 10 dollars. Etc.
Viggy
-
July 14th, 2011, 03:39 PM
#17
Re: Loop Problem
Originally Posted by GCDEF
I don't get stuck in any loop. What is the problem and how do we recreate it? Have you tried the debugger?
To recreate it put
Code:
Payment=Total*MinInterest;
at the end of the loop in calculate.
The reason for this is to reset the minimum payment for each month. If you also add
Code:
cout<<Payment<<" "<<month<<endl;
system("PAUSE");
The code does not actually get stuck the decimal points just keep getting longer. I just do not know how to fix this. I have searched for trimming double on goggle but found nothing. My problem is I do not understand how to do it. My incompetence is the problem. Just asking how is the correct way to do this.
-
July 14th, 2011, 03:42 PM
#18
Re: Loop Problem
Originally Posted by josh26757
To recreate it put
Code:
Payment=Total*MinInterest;
at the end of the loop in calculate.
The reason for this is to reset the minimum payment for each month. If you also add
Code:
cout<<Payment<<" "<<month<<endl;
system("PAUSE");
The code does not actually get stuck the decimal points just keep getting longer. I just do not know how to fix this. I have searched for trimming double on goggle but found nothing. My problem is I do not understand how to do it. My incompetence is the problem. Just asking how is the correct way to do this.
I mean what values does one enter at the prompts to exhibit this behavior. I didn't see it.
-
July 14th, 2011, 03:42 PM
#19
Re: Loop Problem
Originally Posted by MrViggy
How many cents are in a dollar? 1 is 1 cent. 100 is 100 cents, or 1 dollar. 1000 is 10 dollars. Etc.
Viggy
I understand what you are saying just how do you implement it? Better than wasting your time, can you give me a link that explains this? I am fairly new so I need a basic explanation.
-
July 14th, 2011, 03:43 PM
#20
Re: Loop Problem
Originally Posted by josh26757
I understand what you are saying just how do you implement it? Better than wasting your time, can you give me a link that explains this? I am fairly new so I need a basic explanation.
Work with cents instead of dollars. 1 dollar and 11 cents becomes 111 cents. Divide by 100 when you need to output dollars and cents.
-
July 14th, 2011, 03:44 PM
#21
Re: Loop Problem
Originally Posted by GCDEF
I mean what values does one enter at the prompts to exhibit this behavior. I didn't see it.
I am entering 5000 for the bill, 18 for the interest and minimum payment for the selection. This is the example in my Personal Finance class.
-
July 14th, 2011, 03:50 PM
#22
Re: Loop Problem
Originally Posted by GCDEF
Work with cents instead of dollars. 1 dollar and 11 cents becomes 111 cents. Divide by 100 when you need to output dollars and cents.
I will work on changing over the code tonight. I can see there needs to be exception handling going on just in case the user tries to enter cents(157.03). I know I also need to add exception handlers for invalid input but my main focus was just practice for the basic equation and to get better with my code. I know college will help polish me and make me "think outside the box", but I want to get ahead for better grades and understanding.
-
July 14th, 2011, 04:00 PM
#23
Re: Loop Problem
Originally Posted by VladimirF
I think you undercharge the interest:
Code:
//calculate Average Daily Balance
AverageDailyBalance=Total/DaysInCycle;
//Find Total Interest Paid
TotalInterest=AverageDailyBalance*MonthlyInterest;
I wish my credit cards worked that way!
lol!!!
I am happy today and thinking positive
Helps ease the pain!!!
I know that is a lame way to recreate the days in a particular month and I need to write a function to correct it, but on the other hand I will wait tell a unhappy day
-
July 14th, 2011, 04:13 PM
#24
Re: Loop Problem
Originally Posted by josh26757
lol!!!
I am happy today and thinking positive
Helps ease the pain!!!
I know that is a lame way to recreate the days in a particular month and I need to write a function to correct it, but on the other hand I will wait tell a unhappy day
I am not talking about differences in months length (28..31 days).
My point is that what you call AverageDailyBalance is NOT an average daily balance. It is about 30 times less, which makes your interest negligible. You are practically paying down the principal only. But since you do not check for the overpayment on the last month, your calculations result in 34 payments (33 * $150 is $4,950, which is less that your initial amount), whatever the interest is.
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 14th, 2011, 04:18 PM
#25
Re: Loop Problem
While I have so many peoples attention can I ask what would benefit me the most to study? My main concentration is going to be Java in my associates degree then it moves to c++ introduction at the end. The bachelors goes more in depth with c++ and implementation. I know a lot of you have probably been through all this. So what did you have the hardest time on and what do you wish you would have had previous experience with?
I have been watching MIT lectures at acadimicearth.org. As well as videos from
The University of Whales. Very good videos for beginners and a heads up for college. I am self taught so far and these videos are all the learning I have done. I have some O'Reilly books but that is it. Going to band practice, I will check the posts when I get back.
-
July 14th, 2011, 04:18 PM
#26
Re: Loop Problem
Originally Posted by josh26757
...I am trying to work on C++ to get ready for my classes...
Just wanted to note that, other than use of std::cin and std::cout, your code has very little to do with C++.
What book did you say you are using?
Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
Convenience and productivity tools for Microsoft Visual Studio:
FeinWindows - replacement windows manager for Visual Studio, and more...
-
July 14th, 2011, 04:23 PM
#27
Re: Loop Problem
Originally Posted by josh26757
I will work on changing over the code tonight. I can see there needs to be exception handling going on just in case the user tries to enter cents(157.03).
Usually, this is not a case for writing an exception handler in C++. Making a typing mistake is not an "exceptional" condition. It happens all the time.
I know in Java and other languages, they throw exceptions for any little thing that could go wrong. In the C++ world, this usage of exceptions is rarely done. If the code is guaranteed to do something based on a condition, and the guarantee cannot be met due to some circumstance, then that would be a case for exception handling.
For example, an important file missing when it must (not should, but must) be there on the system, or expanding an array to a certain size and it fails due to lack of memory, etc. these would be considered exceptional conditions. Someone with fat fingers typing a number and hitting enter doesn't fit this, IMO.
Regards,
Paul McKenzie
-
July 14th, 2011, 04:29 PM
#28
Re: Loop Problem
Originally Posted by VladimirF
I am not talking about differences in months length (28..31 days).
My point is that what you call AverageDailyBalance is NOT an average daily balance. It is about 30 times less, which makes your interest negligible. You are practically paying down the principal only. But since you do not check for the overpayment on the last month, your calculations result in 34 payments (33 * $150 is $4,950, which is less that your initial amount), whatever the interest is.
Oh I see what I did wrong. I need to add all the interest together or
ex:
Code:
day[1] =571;
day[2]=579;
ect.....
for(int i = 0; i<day.size();i++){total=total+day[i];}
AverageDailyBalance = (total/day.size());
-
July 14th, 2011, 04:33 PM
#29
Re: Loop Problem
Originally Posted by VladimirF
Just wanted to note that, other than use of std::cin and std::cout, your code has very little to do with C++.
What book did you say you are using?
Not really using a book. More like watching lectures. I understand c++ is all about object or classes. I do need to do this and will be a lot more comfortable with it after I start working on java. I should implement classes and objects now. Is that what you are recommending?
-
July 14th, 2011, 04:40 PM
#30
Re: Loop Problem
Originally Posted by josh26757
I can see there needs to be exception handling going on just in case the user tries to enter cents(157.03).
You should separate the input and output format from the internal storage format. Even if you're counting cents internally (so that $157.03 becomes 15703 cents), that doesn't mean that you shouldn't be able to accept "157.03" as an input in dollars. You validate the input, then you convert it to your internal format. Similarly, you can convert your count of cents back to the conventional notation on ouput:
Code:
void outputmoney(ostream &out, int totalcents)
{
int dollars = totalcents/100;
int cents = totalcents%100;
out << "$" << dollars << "." << cents;
}
outputmoney(cout, 15703); // test call
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|