FUNCTIONS..please help

The book im using is the Programming in C++ by D'Orazio

ok my problem is i cant get the function to return the right calculation for p
this is what i have so far


# include <iostream>
# include <cmath>
# include <iomanip>
# include <fstream>
using namespace std;
double power (double,double,double);
int main ()
{
double v,i,p;
int powe;
ifstream Cons ("C:\\POW.DAT");


for (powe =1;powe <=4;powe ++)
{
Cons >> v >> i;
cout<<"Input voltage = "<<v<<" volts,current = "<<i<<" amperes"<<endl;
cout<<"Power consumed by the heater = "<<p<<" watts"<<endl<<endl;


}




system("pause");
return 0;
}
double power (double v,double i, double p)
{


p = v * i;
return p;


}
closed account (z05DSL3A)
Your code is not calling power().

try:
1
2
3
4
5
Cons >> v >> i; 
p=0;
cout<<"Input voltage = "<<v<<" volts,current = "<<i<<" amperes"<<endl;
cout<<"Power consumed by the heater = "<< power(v,i,p) <<" watts"<<endl<<endl;


p is actually redundant:
1
2
3
4
double power (double v,double i)
{ 
	return  v * i;
} 

Last edited on
Topic archived. No new replies allowed.