man pow
my teacher just told us about it and didn't give any paper on it.
thanks.
i have never used double but will give it a try.
when i declare the variables should i use float or...
Hi,
You might like to know that powf() is a 'float' version of pow().
To get some info on pow, type this in a terminal window:-
Code:man pow
b e n
Code:#include <math.h>
Well, it shouldn't be that magic and impossible to find, and the above mentioned man page is extremely clear:I'm surprised your professor told you to use pow() and didn't mention including math.h or anything about how to use it.
POW(3) BSD Library Functions Manual POW(3)
NAME
pow -- power function
SYNOPSIS
#include <math.h>
double
pow(double x, double y);
long double
powl(long double x, long double y);
float
powf(float x, float y);
DESCRIPTION
The pow() functions compute x raised to the power y.
Where do you usually put your includes...?
Part of learning basic programming is more to figure out where to obtain information than to be spoon-fed the code... </old grumpy ex-teacher in c++>
#include <iostream>[B]#include <math.h>[/B]
using namespace std;
int main ( void )
{
// Name - Class - Assignment - Due Date
cout<< "Ben Langodon\n Computer Science\nHomework 10\n4\\3\\08\n\n";
// Variables
float rate; // Annual Interest rate
float rate1; // rate + 1
float term; // Term of loan in years
float term1; // term * 12
float moneyBorrowed; // Amount of money borrowed
float monthlyPay; // Amount paid every month
float rateTerm; // pow( 1 + rate, term)
// Defining of Variables
cout<<"Annual Interest Rate:";
cin>>rate;
cout<<"Term of Loan in Years:";
cin>>term;
cout<<"Amount of Money Borrowed:";
cin>>moneyBorrowed;
// Process
term1 = term * 12;
rate1 = rate + 1;
[B]rateTerm =
powf(float rate,float term);[/B]
monthlyPay = rate1 * rateTerm / rateTerm - 1 * moneyBorrowed;
// Output
cout<<"Amount paid a month:"<<monthlyPay;
}
Part of learning basic programming is more to figure out where to obtain information than to be spoon-fed the code... </old grumpy ex-teacher in c++>
Try one line per include statement:Code:#include <iostream>[B]#include <math.h>[/B] using namespace std;
#include <iostream>
#include <math.h>
Not professor, nor experienced...just taught some lessons in very basic c++ at the local College when I continued (with something completely different) at University...As a professor and experienced programmer, you would say that...
#include <iostream>
#include <math.h>
using namespace std;
int main ( void )
{
// Name - Class - Assignment - Due Date
cout<< "Ben Langodon\n Computer Science\nHomework 10\n4\\3\\08\n\n";
// Variables
float rate; // Annual Interest rate
float rate1; // rate + 1
float term; // Term of loan in years
float term1; // term * 12
float moneyBorrowed; // Amount of money borrowed
float monthlyPay; // Amount paid every month
float rateTerm; // pow( 1 + rate, term)
// Defining of Variables
cout<<"Annual Interest Rate:";
cin>>rate;
cout<<"Term of Loan in Years:";
cin>>term;
cout<<"Amount of Money Borrowed:";
cin>>moneyBorrowed;
// Process
term1 = term * 12;
rate1 = rate + 1;
rateTerm = powf(float rate,float term);
monthlyPay = rate1 * rateTerm / rateTerm - 1 * moneyBorrowed;
// Output
cout<<"Amount paid a month:"<<monthlyPay;
}
Why are you declaring rate and term twice, or at least trying to? Delete the two float words in the powf() function.
well i was trying to say that
rateTerm = 1 + rate to the exponent of term
so them combined i figure would be called rateTerm since its rate and term
#include <iostream>
#include <math.h>
#include<iomanip>
using namespace std;
int main ( void )
{
// Name - Class - Assignment - Due Date
cout<< "Ben Langodon\nComputer Science\nHomework 10\n4\\3\\08\n\n";
// Variables
float rate; // Annual Interest rate
float moneyBorrowed; // Amount of money borrowed
float monthlyPay; // Amount paid every month
float rateTerm; // pow( 1 + rate, term)
// Term in years - Term in months
float term; // Term of loan in years
int term1; // term * 12
// formula variables
float a1; // rate * rateTerm
float a2; // rateTerm - 1
float a3; // a1 / a2
// setpricision
setprecision(2);
// Defining of Variables
cout<<"Amount of Money Borrowed:"<<setw(25);
cin>>moneyBorrowed;
cout<<"Annual Interest Rate:"<<setw(25);
cin>>rate;
cout<<"Term of Loan in years:"<<setw(25);
cin>>term;
// Term * 12, years to months
term1 = term*12;
// 2nd varaibles
cout<<"Term of Loan in months:"<<term1;
// Process
rateTerm = powf(1 + rate,term1);
a1 = rate * rateTerm;
a2 = rateTerm - 1;
a3 = a1/a2;
monthlyPay = a3*moneyBorrowed;
// Output
cout<<setw(25)<<"\n\nAmount paid a month:"<<monthlyPay;
}
rateTerm = powf(1 + rate,term1);
a1 = rate * rateTerm;
a2 = rateTerm - 1;
a3 = a1/a2;
monthlyPay = a3*moneyBorrowed;
Your powf() function is still wrong. You need to keep an eye on the types you are using, or at least cast if you want to treat them as a different type.