ok here is the code without pointers and your probly right i dont think i need them but it wont work with out some kind of some thing else lol
Code:
//this is the main file of my horse betting projest
#include <iostream>
#include <cstdlib>
#include <cstdio>
using namespace std;
int total;
int i;
float accumstake=0.0;
class horse
{
public:
float odds,stake,stakereturn;
};
int main ()
{
cout<<"please enter the total amount of bets u need\n";
cin>>total;
cin.get();
horse h[total];
for (i=0;i<total;i++) //allows user to enter odds
{
cout<<"please enter the odds for the bets in format 1.5\n";
cin>>h[i].odds;
cin.get();
}
for (i=0;i<total;i++)// sets starting stake at 1
{
h[i].stake=1.0;
h[i].stakereturn=h[i].stake*h[i].odds;//sets all returns
}
for (i=0;i<total;i++)//accumalates the total of all stakes of horse objects
{
accumstake= accumstake+h[i].stake;
}
for (i=0;i<total;i++)//levels through the returns once
{
while (h[i].stakereturn<accumstake)
{
h[i].stake++;
h[i].stakereturn=h[i].stake*h[i].odds;
accumstake=accumstake+h[i].stake;
if (h[i].stakereturn<accumstake)
i=0;}
}
//need this to check each h[] to see if the return is
//higher than the accumstake in all h[] objects
cout<<"these are the stakes u need\n";
for (i=0;i<total;i++)
{
cout<<"horse no. "<<i<<" ("<<h[i].stake<<")"<<"\n";
cout<<"return from horse no. "<<i<<" "<<"("<<h[i].stakereturn<<")"<<"\n";
}
cout<<"total stake"<<accumstake<<"\n";
system ("pause");
return 0;}
this part
Code:
for (i=0;i<total;i++)//levels through the returns once
{
while (h[i].stakereturn<accumstake)
{
h[i].stake++;
h[i].stakereturn=h[i].stake*h[i].odds;
accumstake=accumstake+h[i].stake;
if (h[i].stakereturn<accumstake)
i=0;}
}
needs to loop through like this
Code:
while (h[i].stakereturn<accumstake)
{
h[i].stake++;
h[i].stakereturn=h[i].stake*h[i].odds;
accumstake=accumstake+h[i].stake;
if (h[i].stakereturn<accumstake ||
h[i].stakereturn<accumstake ||
h[i].stakereturn<accumstake)
// not [i] but [0]------all the way to------[total]
i=0;}
}
but i cant think how to write it as the array is
undefined in amount of elements
maybe i can use another for loop but i start to get confused lol