Math Error e+006

Hey guys....This is my first post on this forum so forgive any mistakes I may make. Anyway....I have been writing a basic program and I have everything done. But on my code when I need to have my first variable input raised to my third variable input I receive the following:
The first number raised to the third number is: 9.46679e+006

The 9.46679e+006 is my problem.

I'm using the numbers 7.23 as first number, 4.932 as second, and 8.12 as third.
The actual answer is 9466795.0 <---This is what I need it to display...
I have been away from C++ for a year now and probably have forgotton..

Here is my code below:
//------------------------------------------------------------------------------
#include <iostream>
#include <cmath>
using namespace std;
//------------------------------------------------------------------------------
float ReadIn (); //Prototyping ReadIn Function.
float Difference (); //Prototyping Difference Function.
float Power (); // Prototyping Power Function.
float Largest (); // Prototyping Largest Function.
float Smallest (); // Prototyping Smallest Function.
//------------------------------------------------------------------------------
float ReadIn (float& A, float& B, float& C) //ReadIn Function & Sum Function.
{
float SUM;
SUM = A + B + C;
return SUM;
}
//------------------------------------------------------------------------------
float Difference (float& A, float& B) //Difference Function.
{
float dif;
dif = A - B;
return dif;
}
//------------------------------------------------------------------------------
float Power (float& A, float B) // Power Function.
{
float PWR;
PWR = pow(A, B);
return PWR;
}
//------------------------------------------------------------------------------
float Largest (float& A, float& B) // Largest Function.
{
float LGR;
if (A > B)
LGR = A;
if (B > A)
LGR = B;
return LGR;
}
//------------------------------------------------------------------------------
float Smallest (float& A, float& B) //Smallest function.
{
float SML;
if (A < B)
SML = A;
if (B < A)
SML = B;
return SML;
}
//------------------------------------------------------------------------------
int main ()
{
float Num1, Num2, Num3; // Declaring variables.
float SUM, DIF1, DIF2, PWR, PWR2, LGR, LGR2, SML, SML2;

cout << "Please enter your first number: " << endl;
cin >> Num1;
cout << "Please enter your second number: " << endl;
cin >> Num2;
cout << "Please enter your third number: " << endl;
cin >> Num3;
//**************************Function Calls Below********************************
SUM = ReadIn (Num1, Num2, Num3); //Calling the ReadIn function.
DIF1 = Difference (Num1, Num2); // Calling the Difference Function.
DIF2 = Difference (Num1, Num3); // Calling the Difference Function second time.
PWR = Power (Num1, Num2); //Calling the Power Function.
PWR2 = Power (Num1, Num3); // Calling Power Function second time.
LGR = Largest (Num1, Num2); // Calling Largest Function.
LGR2 = Largest (LGR, Num3);// Calling Largest Function second time.
SML = Smallest (Num1, Num2); //Calling Smallest Function.
SML2 = Smallest (SML, Num3); //Calling Smallest Funtion second time.
//**************************Output Below****************************************
cout << "--------------------------------------------------------------------------------" << endl;
cout << "First Number entered: " << Num1 <<endl;
cout << "Second Number entered: " << Num2 << endl;
cout << "Third Number entered: " << Num3 << endl;
cout << "Sum of all numbers is: " << SUM << endl;
cout << "Difference between first and second number entered is: " << DIF1 << endl;
cout << "Difference between first and third number entered is: " << DIF2 << endl;
cout << "The first number raised to the second number is: " << PWR << endl;
cout << "The first number raised to the third number is: " << PWR2 << endl;
cout << "The largest number entered is: " << LGR2 << endl;
cout << "The smallest number entered is: " << SML2 << endl;

system("PAUSE");
return 0;
}
I think you can use fixed e.g
cout<<fixed<<PWR2<<endl;
But how do you know your approximation is "correct"?
@chemley
Can you please use code tags:
[code]int main()[/code] -> int main()
closed account (S6k9GNh0)
I see some rather bad practice here. For starters, pow() can be used directly since it should be implemented wherever the stdlib is present (which should be everywhere a C++ implementation is available). Largest and small can be replaced with ceil and floor functions. And a minus function? Really? Also, don't use system().

Aside from that, http://www.cplusplus.com/forum/beginner/5381/
Last edited on
Thanks buffbill.....That took care of it.

Topic archived. No new replies allowed.