i just write for a small code for the homework, there is a part of if, else statement. but there are a problem. once, I type right stock name, and numbers to buy, it will show "wrong numbers to buy"
for (int m=0; m<j; ++m)
{cout<<"the current stocks in the system: "<<stockArray[m].getCompanyName()<<" "<<stockArray[m].getTradingTicker()<<endl;
}
cout<<"please type which stock do you want to buy"<<endl;
string wantstocks;
cin>>wantstocks;
for(int m=0; m<j; ++m)
{
if (stockArray[m].getCompanyName()==wantstocks||stockArray[m].getTradingTicker()==wantstocks)
{ // int& x=m;
cout<<"how many shares do you want to buy? please enter the number to buy: ";
//}
// else
// cout<<"wrong ticker"<<endl;
int number2;
cin>>number2;
if( (number2>0)&& (number2*(stockArray[m].getSharePrice())<my.getFundsAvailabe()))
{
stockArray[m].setNumberOfShares(stockArray[m].getNumberOfShares()-number2);
my.setFundsAvailabe( my.getFundsAvailabe()-(number2*(stockArray[m].getSharePrice() ) ) ) ;
}
else
cout<<"wrong number to buy"<<endl;
}
else
cout<<"wrong ticker or company to buy";
}
}