How to print values lower than a certain number?
Mar 24, 2011 at 8:46pm UTC
I'm trying to print values lower than a set number but I can't seem to get it to happen. My Program just hangs.
They don't have to be sorted by price, I just need to print all the motorcycles UNDER a certain price, they don't have to be in ascending or descending order.
Here's what I've got so far.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
void PriceList(Motorcycles *firstMotorcycle)
{
int sortPrice;
indata >> sortPrice;
Motorcycles *nodePtr;
nodePtr = firstMotorcycle;
//Motorcycles *overSort;
cout << setw(10) << "Make" << setw(17) << "Model" << setw(15) << "StockNum" << setw(10) <<
"Style" << setw(12) << "Price" << setw(8) << "HP" <<endl;
cout << setw(10) << "----" << setw(17) << "-----" << setw(15) << "--------" << setw(10) <<
"-----" << setw(12) << "-----" << setw(8) << "--" <<endl;
while (nodePtr->Price <= sortPrice)
{
cout << setw(10) << tptr->Manu << setw(17) << tptr->Model << setw(15) << tptr->StockNum << setw(10) <<
tptr->Style << setw(12) << tptr->Price << setw(8) << tptr->Hp <<endl;
nodePtr = nodePtr->nextBike;
}
return ;
}
Thanks
Mar 24, 2011 at 11:27pm UTC
1 2 3 4 5 6 7 8
std::remove_copy_if(
v.begin(),
v.end(),
std::ostream_iterator<int > (std::cout, "\n" ),
std::not1(
std::bind2nd( std::less<int >(), 42 )
)
);
The elements that evaluate true will not be printed.
Mar 24, 2011 at 11:33pm UTC
That's way past where I'm at. You seem to have a lot of experience, could you do it with a while loop or if statement?
Mar 24, 2011 at 11:35pm UTC
Loop over all your Bikes and print them out if you have a value less than whatever you want.
Mar 24, 2011 at 11:51pm UTC
Okay, there seems to be a problem with my infile state ment. When I comment it out and set sortPrice to a number, it works but it just reads a random number in from infile.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
void PriceList(Motorcycles *firstMotorcycle)
{
int sortPrice = 0;
indata >> sortPrice;
Motorcycles *nodePtr;
nodePtr = firstMotorcycle;
cout << "Motorcycle(s) priced under $" << sortPrice <<endl;
cout << setw(10) << "Make" << setw(17) << "Model" << setw(15) << "StockNum" << setw(10) <<
"Style" << setw(12) << "Price" << setw(8) << "HP" <<endl;
cout << setw(10) << "----" << setw(17) << "-----" << setw(15) << "--------" << setw(10) <<
"-----" << setw(12) << "-----" << setw(8) << "--" <<endl;
while (nodePtr)
{
if (nodePtr->Price <= sortPrice)
{
cout << setw(10) << nodePtr->Manu << setw(17) << nodePtr->Model << setw(15) << nodePtr->StockNum << setw(10) <<
nodePtr->Style << setw(12) << nodePtr->Price << setw(8) << nodePtr->Hp <<endl;
}
nodePtr = nodePtr->nextBike;
}
return ;
}
EDIT: I declared price as a double! duh.
Last edited on Mar 25, 2011 at 12:00am UTC
Topic archived. No new replies allowed.