# A little help with this



## EngagewithRage (Oct 8, 2008)

Ok its not really the program i need help with its the equation that i need for the program to work.the program figures out the value of your weight in pennies and your height in quarters. the variables and their values are in the attachment.Math isnt one of my strongest subjects so any help would be cool, and if you see any mistakes in the program itself, feel free to let me know.Thanks in advance


----------



## dm01 (Oct 10, 2006)

This looks like C++, but I can't be absolutely sure.

The C++ arithmetic operands are: addition +, subtraction -, multiplication *, and division /. This assignment only requires multiplication and division, so you don't need to worry too much about rules of precedence.

One more thing: association in C++ is left-to-right, in that:
3*2/7 = .857 ...
3*(2/7) = 0.4285 ...

as if you just typed the numbers into a calculator.

Good luck, and please try to keep your questions away from "do this for me", or you may inadverdantly violate our Rules. A good question would be, "how do the mathematical operands interact?" A not-so-good question is "show me how this equation is supposed to work".

Does that make sense?


----------



## EngagewithRage (Oct 8, 2008)

no, not quite what i was asking, but i get you...ill figure it out, thanks tho, i dont think i worded my question right lol, ill just toy with it till i get it right


----------



## dm01 (Oct 10, 2006)

The general rule of conversions:

if(converting_to > converting_from)
converting_from * conversion_factor;
else
converting_from / conversion_factor;


If you understand that, you can do this.
I tried out your program because I had nothing else I had to || wanted to do. (I tells ya, this C++ is infectious). As long as you remember the rule of association, you will do fine. The underlying structure is sound, that's all I was really checking for though.


----------



## EngagewithRage (Oct 8, 2008)

The program is good, i figured out the equation to calculate a persons value in weight using pennies, only thing i have trouble with is calculating a persons value using their height in quarters

example:

quarters height in MM=1.75
MM per Inch=25.4
value of a quarter=.25?
your height in inches=1(for the sake of testing the equation)

1(yourheightIN)*25.4*1.75/.25==?

the answer should come out to 3.62, i think im missing something to get the right answer but im not sure what, ive been going over and ove this for a couple days now, im really bad at math and im tired of thinking about it. ima just turn it in as is and take whatever grade he gives me if i cant figure this out lol, if anyone has any suggestions it would be greatly appreciated


----------



## dm01 (Oct 10, 2006)

You've forgotten the rule. Here, I'll help you out:

valqrtr = yhghtIN*MMperIN/qrtrhghtMM*qrtrval;
/*3.62 = 1 * 25.4 / 1.75 * .25
the subject's value in quarters is: 
subject's height in inches, converted to milimetres, 
divided by the thickness of a quarter to get the quantity of quarters, and multiplied by the currency value of a quarter
to get the value of the subject's height wrt quarters.*/​


----------



## EngagewithRage (Oct 8, 2008)

holy **** im retarded lol, thanks man, now i can finally turn in my lab5, i really appreciate it, would have taken me forever to figure this out


----------



## dm01 (Oct 10, 2006)

No problem. I have had several "durr" moments myself when someone showed me what I did wrong. Usually I do things that make sense in my head, but cause the compiler to react violently (if I'm lucky and don't crash the system).

Make sure you understand what I did. There is nothing worse in this course than blind copying, which is why I was reluctant to give out the entire answer first off.

You can write an entire C++ application with no numerical math at all, all you need is the right kind of thinking. Variables and constants were developed to try to reduce the amount of number copying and numerical math required, instead placing the emphasis on the logical flow of data. If you haven't learned about this yet, you will get an earful before the semester is through.


----------



## EngagewithRage (Oct 8, 2008)

My professor isnt exactly the greatest "teacher" there is, most of us walk out of classing scratching our heads saying " What the hell was he talking about".I learn most of what know from reading and forums like this. Although ive always been terrible at math, but im getting there. Ive got yet another lab thats gonna have me do things involving math equations.

Objective:

Upon completion of this lab, the student will be able to:

*
Define variables properly to implement their computer program solution
* Begin to use decision statements as switches
*
Properly set up a iteration logic construct
*
Write, compile and run a C++ program in the Linux or Cygwin environment

Lab Instructions:

You want to buy a car but no one other than your parents will lend you any money. When you approach your father he agrees to loan you the money but only if he can charge you 6% simple interest on the outstanding balance. He requests that you create a C++ program that will do the calculations rather than using some pre-written. He also asks you to determine how many years you want the loan for.

In your analysis you decide that you will split the principle into equal parts and then add the interest for the month to the principle to determine the monthly payment. Then you can subtract the payment of the principle from the balance owed and recalculate the principle balance for the next payment.

You would like to find how much you will pay each month for the term of the loan. The output should look something like this

Enter the amount of the loan: 8000
Enter the number of years of the loan: 3

Payment	Balance	Principle Due	Interest Due	Total Due
1 8000 250 40 290
2 7750 250 38.75 288.75
3 7500 250 37.5 287.5
:
:
32 250 250 1.25 251.25


As an extra challenge keep track of the interest that is paid and display it at the end of the report.

Final product will contain: 

* 6 Step Process Sheet with the above collected data from above.
* The C++ source that solves the problem

Grading:

Your grade will be based upon the following:

* You were able to follow the instructions above and complete the task.
* You found read and followed the instructions for emailing me !
* The lab was emailed to me before the due date.


Im gonna try my best to figure this one out on my own though. Wish me luck


----------



## dm01 (Oct 10, 2006)

Good luck. I had a similar lab earlier that I still have the codes for if you need help later. The calculation is quite difficult to get exactly right, but I'm sure you'll manage.

Now, I have to complete a very annoying assignment that has been bothering me for several days. I hope I can get it done and still have time to read the Criminology that I have been ignoring for the past few days.


----------



## EngagewithRage (Oct 8, 2008)

Haha i feel your pain man, actually i got the mat down, and im working on writing the program heres what i got so far

#include <iostream>
#include <iomanip>
using std::cout;
using std::endl;
using std::cin;
using std::setprecision;
using std::setw;
int main()
{

double loan, months;
int years;
double intrate = .06;
double totdue, pbal, intdue;
double const pdue = 250;
double baldue;
int mnthsinyr = 12;
double totalint;

cout << "Enter the amount of the loan: "<< endl;
cin >> loan;

cout << "Enter the number of years of the loan: " <<endl;
cin >> years;

do
{
months = mnthsinyr * years;
totalint = loan * intrate * years;
intdue= totalint / months;
totdue = pdue + intdue;
pbal = loan - totdue + intdue;
}

while ( loan < 0, intdue < 0, totdue < 0)

cout << setprecision (4);

cout << setw(1)<< "Payment Balance" << setw(3)<< "Principle Due "<< setw(3)<< "Interest Due" << setw(3)<< "Total Due"<<endl;

cout << setw(1)<< pbal << setw(3) << pdue << setw(3) << intdue << setw(3) << totdue<<".\n";

}
}
return 0;
}

im sure its not correct, but im still working on it, yeah the coes would help me out alot, just to make sure im going in the right direction. Thanks for the help youve given, and goodluck with your assignments man, and i heop u get around to reading that criminology that u need to, i just finished a sociology exam that i crammed for right before the test, i hope i passed.Well aywho later man, look forward to ur reply


----------



## EngagewithRage (Oct 8, 2008)

yep,im more than positive alot of the code is wrong, but we havent really gone in depth over do while loops, or how to do this type of program. in a couple days ill have it ironed out.well im off to bed im tired as F***.


----------



## dm01 (Oct 10, 2006)

That's because the comma (",") is not the logical operator "AND". Try using "&&" instead of "," .

Get a good rest and tackle this again in the morning. Your logic seems sound, but I would have to compile the code to be sure. My processor's at one-quarter power right now so that's not something I can do at the moment.

This is not how mine was constructed, but I guess you have to follow the assignment.
Good night.


----------



## EngagewithRage (Oct 8, 2008)

Well i got a basic idea of what i do, but im not sure where to start, or what to do first, im kind of spent on this tbh. ive gota week before its due so ive got sum time.thanks for everything your doing man, really appreciate it.I know i need a while loop to keep track of the payments made, until the loan is payed off, i know i need a variable to keep track of the interest paid, lining everything up like the example on my labsheet is driving me crazy. The loop i made doesnt work just displays the first payment and so on, doesnt go thru till the loan is payed off. ughhh wheres my gun..... not sure if should post this in a new thread or not


----------



## EngagewithRage (Oct 8, 2008)

would it be at all possible to get your sourcecode for the program u said was similar to this one? would help if i had something to reference to.friday im going down the the lab at my college to get more help, i dont wanna just copy it and still not know what the hell im doing.


----------



## dm01 (Oct 10, 2006)

Mine is a little different, but here goes:


```
#include <fstream>
#include <iostream>
#include <conio.h>
using namespace std;

#define in_file "mortgage_data.txt"
#define out_file "mortgage_pymt.txt"

void main()
{
	ifstream ins;
	ofstream outs;
	
	float principal, interest, N, pymt_month;
	int charge_service;
	ins.open(in_file);
	outs.open(out_file);
	ins >> principal >> interest >> N >> charge_service;

	cout << "The principal of this loan is: " << principal << endl;

	cout << "The interest rate for this loan is: " << interest << endl;

	cout << "The service charge is: $"<< charge_service << endl;

	cout << "The number of periods for this loan is: " << N << endl;

	pymt_month = (principal * (1 + interest) + charge_service)/N;

	cout << "The monthly payment for this loan is $" << pymt_month << endl;

	_getch();

}
```
Mine uses external files to get the information, but the equation is correct.


Instead of 

```
do
{
months = mnthsinyr * years;
totalint = loan * intrate * years;
intdue= totalint / months;
totdue = pdue + intdue;
pbal = loan - totdue + intdue;
}

while ( loan < 0, intdue < 0, totdue < 0)
```
Try a while loop with the condition related to number of years.

Counters are fairly simple, just add variable++ to the end of the loop.


----------



## EngagewithRage (Oct 8, 2008)

Thanks man, ill get working on it, hopefully next time you hear from me the program will be working.Thanks for all your help


----------



## EngagewithRage (Oct 8, 2008)

Okay man code is done now comes "the prettying up" which i can do on my own, im just curious though, when i run my loop, rather than stoppingwhen the loan is paid off, it keeps going thru the whole 36 months when it should stop when the loan is paid off, im not sure if it matters buuuuut. Is there a way i can make it stop when the loan is paid off?i tried an "if" statement didnt seem to work, or maybe i did it wrong. also i need to keep track of all the interest paid, i tried a "while" statement couldnt get that to display the interest paid at the end of the program.any pointers? Heres my code.

#include <iostream>
using std::cout;
using std::endl;
using std::cin;
#include <iomanip>
using std::fixed;
using std::showpoint;
using std::setprecision;
using std::setw;
int main()
{

double loan, mnths;
int years;
double intrate = .06;
double totdue, newbal, intdue;
double const pdue = 250;
double baldue;
int const mnthsinyr = 12;
double totalint;
double rate, totalintdue;

cout << "Enter the amount of the loan: ";
cin >> loan;

cout << "Enter the number of years of the loan: ";
cin >> years;
cout<<""<<endl;

cout <<setw(0)<< "Payment Balance" << setw(15) << "Principle Due" <<setw(18)<<"Interest Due"<<setw(17)<<"Total Due" << endl;

mnths = mnthsinyr * years;
while (mnths > 0)
{
cout <<setprecision(5)<<showpoint;

rate = intrate / mnthsinyr;
totalint = loan * rate * mnths;
intdue= totalint / mnths;
totdue = pdue + intdue;

cout <<setw(0)<<loan<<setw(17) << pdue<<setw(19) << intdue<<setw(20)<< totdue <<endl;
newbal = loan - totdue + intdue;
loan = newbal;
mnths--;
}
totalintdue = intdue+intdue;
while (intdue > 0)
{
cout <<totalintdue<<endl;
intdue--;
}
return 0;
}


----------



## jamiemac2005 (Jul 5, 2007)

I assume that when loan is less than or equal to 0 that the loan is payed off?

If it is you could change your while loop to something like:

```
while (mnths > 0 && loan>0)
```

Cheers,
Jamey


----------



## EngagewithRage (Oct 8, 2008)

ah cool man, i made it "while (mnths >= 0 && loan >= 0)", i like the way it looks, i jut cant figure out how to add up all the interest paid and display it at the end. the while loop i made isnt working, im still working on it though


----------



## dm01 (Oct 10, 2006)

```
totalintdue = intdue+intdue;
```
should be:


```
totalintdue = totalintdue + intdue
```
and moved two lines up to be inside the while loop.

Don't forget to initialize totalintdue=0; in your global vars.


----------

