On Jun 20, 12:37 pm, Scoots <(EMail Removed)> wrote:
> A couple points.
>
> Shouldn't:
> new_base = new_base + base be new_base = new_base * base
>
> (just a suggestion)
> Also, what inputs have you tried it with? A large negative exponent
> like that is often a sign of what is known as floating point
> imprecision. Generally, you'll only notice this around 0, and it
> comes from the ability of the floating point to show very large
> numbers or very very small. Think scientific numbers. An operation
> that it expects to be a zero doesn't necessarily actually end up at
> zero.
>
> Final question though, you DO have stdio included, right?
>
> On Jun 20, 1:20 pm, mahesh <(EMail Removed)> wrote:
>
>
>
> > Hi all,
> > I have following code that is supposed to increase the power by
> > specified value.
> > int main()
> > {
>
> > system("cls");
> > int i, exponent;
> > double base;
> > double new_base=0.0;
> > ofstream powerfile("power.txt",ios::app);
> > cout <<"Enter the base:\n";
> > cin >> base;
> > cout <<"Enter the exponent:\n";
> > cin >> exponent;
> > //cout << base;
> > for (i=0; i< exponent ; i++)
> > {
> > new_base = new_base + base;
>
> > }
> > cout <<"The final powered output is :\n" << new_base;
> > system("PAUSE");
> > return 0;
>
> > }
>
> > but the output that shows up in the screen is:
> > The final powered output is :
> > 3.32222e31204 (some weird value).
> > for every input.
> > What could be the reason for that??
> > Thanks in advance Hide quoted text 
>
>  Show quoted text 
I included #include <cstdio> as a header and all the required header
file.
I wanted to use addition rather than multiplication because addition
takes less time then multiplication.
I tried with 2 as base and 2 as exponent but output was like i
mentioned above rather than 4.
any more guidence on this.
