I need C# help bad... ALL HELP APPRECIATED - Page 2 - Overclock.net - An Overclocking Community
Forum Jump: 

I need C# help bad... ALL HELP APPRECIATED

Reply
 
Thread Tools
post #11 of 60 (permalink) Old 02-07-2012, 07:27 PM
New to Overclock.net
 
brodieboy143's Avatar
 
Join Date: Jan 2009
Location: Sydney, Australia
Posts: 306
Rep: 22 (Unique: 18)
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;
}



brodieboy143 is offline  
Sponsored Links
Advertisement
 
post #12 of 60 (permalink) Old 02-07-2012, 07:37 PM
Did you say Abe Lincoln?
 
.theMetal's Avatar
 
Join Date: May 2011
Location: Colorado
Posts: 3,144
Rep: 89 (Unique: 74)
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 ^^

Spitting in the Stream of Consciousness
Colorado Overclockers
[Official] Fractal Design Node 304 Owners Club
The Donbot
(12 items)
Crushinator
(10 items)
CPU
i7 3770 @ (4.2~4.4)
Motherboard
ASUS P8Z77-I Deluxe
GPU
MSI 1070 Gaming X
RAM
16gig Crucial Tactical LP (@2000)
Hard Drive
Crucial BX100 500gb
Hard Drive
3TB hard drive
Power Supply
Silverstone ST55F-G
Cooling
Phanteks PH-TC14PE
Case
Phanteks Evlov ITX
Monitor
BenQ 27inch IPS (2560x1440)
Keyboard
Blackwidow Tournament
Mouse
Logitech G203 Prodigy
CPU
i5 2320
Motherboard
Asrock H61M-VG4
GPU
EVGA GTX 970
RAM
8gig Samsung LowPro
Hard Drive
Samsung 840 Evo 250gb/WD Black 640gb
Power Supply
Rosewill Hive 550
Case
Apevia X-ENERQ Pink
Monitor
Asus 24 inch (1080p)
Keyboard
Sades Mechanical w/blues
Mouse
Razer Abyssus 2014
▲ hide details ▲


.theMetal is offline  
post #13 of 60 (permalink) Old 02-07-2012, 07:41 PM - Thread Starter
New to Overclock.net
 
Join Date: Apr 2008
Location: GA, USA
Posts: 981
Rep: 46 (Unique: 45)
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
Zaxbys is offline  
Sponsored Links
Advertisement
 
post #14 of 60 (permalink) Old 02-07-2012, 07:43 PM - Thread Starter
New to Overclock.net
 
Join Date: Apr 2008
Location: GA, USA
Posts: 981
Rep: 46 (Unique: 45)
Zaxbys is offline  
post #15 of 60 (permalink) Old 02-07-2012, 07:59 PM
New to Overclock.net
 
brodieboy143's Avatar
 
Join Date: Jan 2009
Location: Sydney, Australia
Posts: 306
Rep: 22 (Unique: 18)
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



brodieboy143 is offline  
post #16 of 60 (permalink) Old 02-07-2012, 08:09 PM - Thread Starter
New to Overclock.net
 
Join Date: Apr 2008
Location: GA, USA
Posts: 981
Rep: 46 (Unique: 45)
I get this error frown.gif(

375
Zaxbys is offline  
post #17 of 60 (permalink) Old 02-07-2012, 08:11 PM
New to Overclock.net
 
brodieboy143's Avatar
 
Join Date: Jan 2009
Location: Sydney, Australia
Posts: 306
Rep: 22 (Unique: 18)
change your declaration of cost to

double cost = 0;



brodieboy143 is offline  
post #18 of 60 (permalink) Old 02-07-2012, 08:13 PM - Thread Starter
New to Overclock.net
 
Join Date: Apr 2008
Location: GA, USA
Posts: 981
Rep: 46 (Unique: 45)
It ran!

How did that fix it?
Zaxbys is offline  
post #19 of 60 (permalink) Old 02-07-2012, 08:15 PM
New to Overclock.net
 
brodieboy143's Avatar
 
Join Date: Jan 2009
Location: Sydney, Australia
Posts: 306
Rep: 22 (Unique: 18)
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.



brodieboy143 is offline  
post #20 of 60 (permalink) Old 02-07-2012, 08:22 PM - Thread Starter
New to Overclock.net
 
Join Date: Apr 2008
Location: GA, USA
Posts: 981
Rep: 46 (Unique: 45)
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?
Zaxbys is offline  
Reply

Quick Reply
Message:
Options

Register Now

In order to be able to post messages on the Overclock.net - An Overclocking Community forums, you must first register.
Please enter your desired user name, your email address and other required details in the form below.
User Name:
If you do not want to register, fill this field only and the name will be used as user name for your post.
Password
Please enter a password for your user account. Note that passwords are case-sensitive.
Password:
Confirm Password:
Email Address
Please enter a valid email address for yourself.
Email Address:

Log-in



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page


Forum Jump: 

Posting Rules  
You may post new threads
You may post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off