Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › I need C# help bad... ALL HELP APPRECIATED
New Posts  All Forums:Forum Nav:

I need C# help bad... ALL HELP APPRECIATED - Page 2

post #11 of 60
Quote:
Originally Posted by .theMetal View Post

I think you need to say:
if (GalofFuel >= 0 && GalofFuel <= 99.9)
{
(Rate * GalofFuel) + Surcharge1
}
else
{
Pass; <--- Or leave this part our, or whatever else you need it to do.
}
Something along those lines.

Beat me to it.

I hate typing on my phone so ill do my best to explain it here


what you want is this:

if ((GalofFuel >= 0) && (GalofFuel <= 99.9))
{
(Rate * GalofFuel) + Surcharge1;
}

each program statement like must end with a semicolon,

If statements need only the braces to enclose their statements, no need for any form of do (do is used for loops)


Your program will most likely end up looking something like this:

double Rate1 = 2.29;
double Rate2 = 2.24;
double Rate3 = 2.19;

double Surcharge1 = 29.99;
double Surcharge2 = 24.99;
double Surcharge3 = 19.99;

double cost;

if ((GalofFuel >= 0) && (GalofFuel <= 99.9))
{
cost = (Rate1 * GalofFuel) + Surcharge1;
}
else if ((GalofFuel >= 100) && (GalofFuel <= 249.99))
{
cost = (Rate2 * GalofFuel) + Surcharge2;
}
else if (GalOfFuel > 250)
{
cost = (Rate3 * GalofFuel) + Surcharge3;
}
Edited by brodieboy143 - 2/7/12 at 7:30pm
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
post #12 of 60
Quote:
Originally Posted by brodieboy143 View Post

Beat me to it.
I hate typing on my phone so ill do my best to explain it here
what you want is this:
if ((GalofFuel >= 0) && (GalofFuel <= 99.9))
{
(Rate * GalofFuel) + Surcharge1;
}
each program statement like must end with a semicolon,
If statements need only the braces to enclose their statements, no need for any form of do (do is used for loops)
Your program will most likely end up looking something like this:
double Rate1 = 2.29;
double Rate2 = 2.24;
double Rate3 = 2.19;
double Surcharge1 = 29.99;
double Surcharge2 = 24.99;
double Surcharge3 = 19.99;
double cost;
if ((GalofFuel >= 0) && (GalofFuel <= 99.9))
{
cost = (Rate1 * GalofFuel) + Surcharge1;
}
else if ((GalofFuel >= 100) && (GalofFuel <= 249.99))
{
cost = (Rate2 * GalofFuel) + Surcharge2;
}
else if (GalOfFuel > 250)
{
cost = (Rate3 * GalofFuel) + Surcharge3;
}

yup he's got it right there ^^
The Donbot
(12 items)
 
Crushinator
(10 items)
 
Lenovo T450S
(6 items)
 
CPUMotherboardGraphicsRAM
i5 2320 Asrock H61M-VG4 EVGA GTX 970 8gig Samsung LowPro 
Hard DriveMonitorKeyboardPower
Samsung 840 Evo 250gb/WD Black 640gb Asus 24 inch (1080p) Sades Mechanical w/blues Rosewill Hive 550 
CaseMouse
Apevia X-ENERQ Pink Logitec G100s 
CPUMotherboardGraphicsRAM
i5 5300u @ 2.90 Lenovo HD Graphics 5500 12 gigs 
Hard DriveOS
Samsung 250g SSD Windows 10 
  hide details  
Reply
The Donbot
(12 items)
 
Crushinator
(10 items)
 
Lenovo T450S
(6 items)
 
CPUMotherboardGraphicsRAM
i5 2320 Asrock H61M-VG4 EVGA GTX 970 8gig Samsung LowPro 
Hard DriveMonitorKeyboardPower
Samsung 840 Evo 250gb/WD Black 640gb Asus 24 inch (1080p) Sades Mechanical w/blues Rosewill Hive 550 
CaseMouse
Apevia X-ENERQ Pink Logitec G100s 
CPUMotherboardGraphicsRAM
i5 5300u @ 2.90 Lenovo HD Graphics 5500 12 gigs 
Hard DriveOS
Samsung 250g SSD Windows 10 
  hide details  
Reply
post #13 of 60
Thread Starter 
When I put that into the compiler and execute the program. It asks the user for input and after I put in the number of gallons it goes no further as if it is not doing the rest of the equation but the program runs
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #14 of 60
Thread Starter 
375
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #15 of 60
You'll need some form of output statement at the end, along the lines of:

Console.Write("The cost of this amount is: $" + cost );

But of course, you'll also have to apply the appropriate discounts based on income and age to fully satisfy the question. smile.gif
Edited by brodieboy143 - 2/7/12 at 8:03pm
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
post #16 of 60
Thread Starter 
I get this error frown.gif(

375
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #17 of 60
change your declaration of cost to

double cost = 0;
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
post #18 of 60
Thread Starter 
It ran!

How did that fix it?
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
post #19 of 60
The compiler sees that cost is not assigned a value in all code paths (e.g. if the value was negative, none of the branches of the if statement would execute) so it is entirely possible that it never gets assigned a value.

By declaring it equal to 0, you make sure that it always has a value, even if it gets modified later on in the code.
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
Main System
(18 items)
 
Server
(11 items)
 
 
CPUCPUMotherboardGraphics
Intel Xeon X5660 Intel Xeon X5660 Intel S5520UR Onboard 
RAMHard DriveHard DriveCooling
Samsung 24GB (6x4GB) DDR3 ECC REG 1333MHz 500GB Samsung 2.5" SATA 250GB Seagate 3.5" SATA Cooler Master Hyper 212 EVO + TX-3 
OSPowerCase
Windows Server 2012 x64 Dell OEM PSU 375W Antec 900 II (Modified) 
  hide details  
Reply
post #20 of 60
Thread Starter 
Gotcha. Now how on earth do I take discounts based on age? How do I run a SEPARATE if statement in the program and ask the user to input their age?
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  hide details  
Reply
Zaxbuild Mk II
(15 items)
 
  
CPUMotherboardGraphicsRAM
Intel 2500k Asus P67 WS Revolution EVGA GTX 670 SC 4GB 2x4gb G.Skill Rip Jaws CL6 
Hard DriveOptical DriveCoolingOS
Crucial M4 128gb & Crucial C300 60gb SSD & 2x 1... Asus 24x CD/DVD-RW XSPC RASA 240 Kit Windows 7 Pro 64bit 
MonitorKeyboardPowerCase
4 x ASUS VN247H-P's in Surround + Accessory Logitech G15 Corsair HX750 NZXT Phantom-White 
MouseMouse PadAudio
Logitech G5 Razer Kabuto Asus Xnonar DX 
  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 › I need C# help bad... ALL HELP APPRECIATED