Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Print values under a certain number?
New Posts  All Forums:Forum Nav:

Print values under a certain number?

post #1 of 5
Thread Starter 
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.

Code:

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;

    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
post #2 of 5
I would just use two arrays. Make a loop the check the price and if its under that price put it into the other array. The when your done print out the second array.
    
CPUMotherboardGraphicsRAM
i7 970 4.15 @ ~1.39v HT ON, Turbo Off EVGA x58 3x SLI 2x EVGA GTX 980 SLI (watercooled), 1x EVGA GTX ... 6 GB 1600 OCZ DDR3 Gold Edition 7-7-7-18 @1475Mhz 
Hard DriveOptical DriveOSMonitor
Samsung 840 SSD 250GB, 2xSamsungF3 1TB (Raid0) 22x Super Multi, 8x Blu-ray Reader Windows 7 Ultimate x64 2x Yamakasi Catleap Q270s (2560x1440) 
PowerCaseMouseAudio
Kingwin 1000w Platinum HAF 932 Black Interior Logitech G500 Logitech Z5500 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 970 4.15 @ ~1.39v HT ON, Turbo Off EVGA x58 3x SLI 2x EVGA GTX 980 SLI (watercooled), 1x EVGA GTX ... 6 GB 1600 OCZ DDR3 Gold Edition 7-7-7-18 @1475Mhz 
Hard DriveOptical DriveOSMonitor
Samsung 840 SSD 250GB, 2xSamsungF3 1TB (Raid0) 22x Super Multi, 8x Blu-ray Reader Windows 7 Ultimate x64 2x Yamakasi Catleap Q270s (2560x1440) 
PowerCaseMouseAudio
Kingwin 1000w Platinum HAF 932 Black Interior Logitech G500 Logitech Z5500 
  hide details  
Reply
post #3 of 5
Thread Starter 
I'm using linked lists and a struct. Does this still apply?
If it were an array I wouldn't have to think twice about it but I'm new at linked lists.
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
post #4 of 5
Quote:
Originally Posted by skatingrocker17 View Post
I'm using linked lists and a struct. Does this still apply?
If it were an array I wouldn't have to think twice about it but I'm new at linked lists.
Oh....
We start link lists after spring break so I'm afraid I'm going to be pretty useless
http://www.cprogramming.com/
^^That's always been a good resource for me when I'm stuck. Maybe it will have something?
    
CPUMotherboardGraphicsRAM
i7 970 4.15 @ ~1.39v HT ON, Turbo Off EVGA x58 3x SLI 2x EVGA GTX 980 SLI (watercooled), 1x EVGA GTX ... 6 GB 1600 OCZ DDR3 Gold Edition 7-7-7-18 @1475Mhz 
Hard DriveOptical DriveOSMonitor
Samsung 840 SSD 250GB, 2xSamsungF3 1TB (Raid0) 22x Super Multi, 8x Blu-ray Reader Windows 7 Ultimate x64 2x Yamakasi Catleap Q270s (2560x1440) 
PowerCaseMouseAudio
Kingwin 1000w Platinum HAF 932 Black Interior Logitech G500 Logitech Z5500 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
i7 970 4.15 @ ~1.39v HT ON, Turbo Off EVGA x58 3x SLI 2x EVGA GTX 980 SLI (watercooled), 1x EVGA GTX ... 6 GB 1600 OCZ DDR3 Gold Edition 7-7-7-18 @1475Mhz 
Hard DriveOptical DriveOSMonitor
Samsung 840 SSD 250GB, 2xSamsungF3 1TB (Raid0) 22x Super Multi, 8x Blu-ray Reader Windows 7 Ultimate x64 2x Yamakasi Catleap Q270s (2560x1440) 
PowerCaseMouseAudio
Kingwin 1000w Platinum HAF 932 Black Interior Logitech G500 Logitech Z5500 
  hide details  
Reply
post #5 of 5
Thread Starter 
Quote:
Originally Posted by Klue22 View Post
Oh....
We start link lists after spring break so I'm afraid I'm going to be pretty useless
http://www.cprogramming.com/
^^That's always been a good resource for me when I'm stuck. Maybe it will have something?
I'll check that site out. I would recommend cplusplus.com if you ever need it.

EDIT:
Okay, there seems to be a problem with my infile statement. When I comment it out and set sortPrice to a number, it works but it just reads a random number in from infile.

Code:

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;



Duh. figured it out. I declared price as a double and read it in as in integer
Edited by skatingrocker17 - 3/24/11 at 5:02pm
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
    
CPUMotherboardGraphicsGraphics
Core i7 930 @ 4004Mhz 1.29 V Gigabyte GA-X58A-UD3R XFX Radeon 6970 nVidia 8800GTX 
RAMHard DriveOptical DriveOptical Drive
G. SKILL 6GB 1333Mhz @ 1455Mhz OCZ Vertex 3 120GB / Seagate 500GB Lite-On DVD-RW TSSTcorp DVD/RW 
CoolingOSMonitorMonitor
Prolimatech Megahalems Windows 7 x64 Professional Samsung S24A350H Dell 20" LCD 
MonitorMonitorKeyboardPower
MAG 17" LCD Samsung 50" Plasma  Focus FK-2001 Mechanical Corsair TX750 
CaseMouseMouse PadAudio
Cooler Master Storm Scout (Modded) Razer Abyssus Disney's Mickey Mouse with circuits JVC MX-GT700 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Print values under a certain number?