error mgs when trying to compute "for loop"

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2004
Posts: 1
Reputation: dkm30 is an unknown quantity at this point 
Solved Threads: 0
dkm30 dkm30 is offline Offline
Newbie Poster

error mgs when trying to compute "for loop"

 
-1
  #1
Nov 11th, 2004
I'm new to C++, and I'm trying to solve a problem to compute an exponent of an integer to a float. The following is the psuedo code:

Declare x as a float
Declare y as an integer
Declare i as an integer
Declare result as a float

Input x //any float
Input y //positive integer

set result = 1 //intial valuue

For i = 1 to y
result = result *x

end for

output result


I have no problem with declaring the variables or reading in the variables. I have problems with my calculations using the "for loop". This is what I have so far:

For (i = 1; y>=0; i++);
{
result = result *x;
End for
}


The program is suppose to allow the user to input the variables (x,y) to solve x^y. I know a number multiplied by itself would give you the exponent, but I'm missing something to allow me to do that.

Thanks in advance for your help.

dkm30
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 220
Reputation: frrossk is an unknown quantity at this point 
Solved Threads: 9
frrossk's Avatar
frrossk frrossk is offline Offline
Posting Whiz in Training

Re: error mgs when trying to compute "for loop"

 
0
  #2
Nov 11th, 2004
Originally Posted by dkm30
For (i = 1; y>=0; i++);
As y is always > 0 (input from user), then your test condition in "for" loop is always true, so the loop is infinite. I think is better to write "for (i=1; i<=y; i++)".
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC