For Loop Problems?

I'm working on a class project and I almost have it completed. The very first loop is a For loop and for some reason it doesn't seem to be doing what I'd like it to do.

I have to get player input (a number) for the iLucky variable. Then that number needs to be added to every number leading up to it. This is basically the idea of that first For loop. Problem is, if I input anything under 6, it outputs to 0 when the calculations start.


#include <iostream>
using namespace std;

int main()
{
int iPlayerAngle; // ask the player for an initial angle
float fPlayerSpeed, fProjectile; //ask the player for an initial speed
float fDistanceFormula = 0; // X value for calculating the distance traveled
int iTries = 0; // tries the player has made
int iLucky; // varying the Target by getting user input to generate a random number
int iNumbersAdded; // used in calculating the target distance
float fRand_number = 0; // the distance of the target


cout << "Welcome to the Text-Based Artillery Game!";
cout << "\n\nPut '0' in response to Angle or Speed to exit the program.";

/* Calculating a "Random" Number for the Target's distance */

cout << "\n\nEnter your lucky number: \n";
cin >> iLucky;

for (int i=1; i<iLucky; i++)
{
iNumbersAdded = iLucky + i;
cout << iNumbersAdded;
}

while (iNumbersAdded > 10)
{
fRand_number = (iNumbersAdded - 9);
//break;

}


do //Game Loop Beginning
{


cout << "\nThe target is a distance of " << fRand_number << " away.\n";

cout << "\n\nTry to get a distance between " << ( fRand_number - 0.5 );
cout << " and " << (fRand_number + 0.5);


/******* Get Angle *********/

cout << "\n\nChoose an angle of 15, 30, 45, 60, or 75: ";

do
{
cin >> iPlayerAngle;

if( iPlayerAngle > 0, iPlayerAngle < 90, (iPlayerAngle % 15) == 0 )
if( iPlayerAngle == 0)
return 0;
else
break;
else
cout << "That's not a valid angle. It must be one of the five given values.\n";


} while( iPlayerAngle <= 0, iPlayerAngle > 90, (iPlayerAngle % 15) != 0 );




/******** Get Speed **********/

cout << "\nNow choose an initial speed from 1 - 10: ";

do
{
cin >> fPlayerSpeed;

if( fPlayerSpeed >= 1.0, fPlayerSpeed <= 10.0 )
if( fPlayerSpeed == 0 )
return 0;
else
break;
else
cout << "That is not a valid speed. It must be between 1.0 and 10.0.\n";

} while( fPlayerSpeed = 0, fPlayerSpeed < 1.0, fPlayerSpeed > 10.0 );


/******** get X value for Distance Formula *********/

switch( iPlayerAngle )
{
case 15:
fDistanceFormula = 0.5;
break;
case 30:
fDistanceFormula = 0.866;
break;
case 45:
fDistanceFormula = 1.0;
break;
case 60:
fDistanceFormula = 0.866;
break;
case 75:
fDistanceFormula = 0.5;
break;
}


/******* Calculate the distance the projectile flew ***********/

fProjectile = fPlayerSpeed * fPlayerSpeed * fDistanceFormula / 10;

cout << "\nYour projectile flew a total distance of: " << fProjectile << "\n\n";
++iTries;



} while( (fProjectile < (fRand_number - 0.5)) || (fProjectile > (fRand_number + 0.5)) ); // Game Loop End



iTries == 1 ? cout << "It only took you 1 try!" : cout << "It took you " << iTries << " tries!\n\n";



std::cin.sync();
std::cin.get();
return 0;
}
traditionally you would have something equal ilucky then while its greater than zero do -- and then just add it to lucky
Figured it out! Silly mistake! Forgot to make sure that the number that resulted from that For loop became the fRand_number. Silly me!! :P
Topic archived. No new replies allowed.