Overclock.net - Overclocking.net
     
 
Home Gallery Reviews Blogs Register Today's Posts Mark Forums Read Members List


Go Back   Overclock.net - Overclocking.net > Software, Programming and Coding > Coding and Programming > Application Programming

Reply
 
LinkBack Thread Tools
Old 10-12-09   #1 (permalink)
Mobo Master
 
Starbuck5000's Avatar
 
intel nvidia

Join Date: May 2008
Location: England
Posts: 1,031

Rep: 70 Starbuck5000 is acknowledged by some
Unique Rep: 63
Trader Rating: 4
Default C# Doesn't like my Else's

So started working on a "Vending Machine" program in C# however All of my else's get flagged. I realise that you can use the switch function instead but before i start changing it I'd like to get to the bottom of why I am getting this error.



Cheers
Attached Thumbnails
C# Doesn't like my Else's-else-errors.jpg  
__________________
Electrical Engineering and Computer Science Student (Joint Bsc Hons)
STUDENT FINANCE HURRY UP!!!

Has far to many components for a 20 year old, and while you're at it forgive my spelling, the keyboard is dyslexic

Quote:
Originally Posted by Tator Tot View Post
Ah the dickery.

Sadly enough, I don't like being a dick in game. It's much more fun flaunting your junk IRL.

System: 24/7 rig, now with less powah than the bench
CPU
W3540
Motherboard
Evga X58 LE
Memory
3x2GB OCZ Golds
Graphics Card
Evga GTX295
Hard Drive
Perc 5i; 4 WDC3200AAKS's Raid 5, 1TB Caviar Green
Sound Card
Asus Xonar D2X
Power Supply
1000W Thermaltake modular
Case
Lian Li PC-A71
CPU cooling
EK-Supreme/BIX420
GPU cooling
EK full cover
OS
Windows 7 Pro - Retail MSDN-AA
Monitor
20.1" LG
Starbuck5000 is offline   Reply With Quote
Old 10-12-09   #2 (permalink)
PC Gamer
 
Daney's Avatar
 
intel nvidia

Join Date: Apr 2009
Location: South-West, UK.
Posts: 1,233

Rep: 137 Daney is acknowledged by manyDaney is acknowledged by many
Unique Rep: 123
Trader Rating: 0
Default

= is used for writing
== is used for reading.

Change the = in the Else's/If's to == and it should be fine and dandy, good luck

Edit: You should also use "C" to check if it's C.
__________________
Steam ID: prodaney
Epic thread

System: Acer Aspire 5633 WLMi
CPU
Intel Mobile Core 2 Duo T5500
Motherboard
Grapevine(Acer)
Memory
4GB (333MHz)
Graphics Card
nVidia GeForce 7300 Go
Hard Drive
160GB (SATA 150Gb/s)
Power Supply
N/A - Running off mains.
OS
Windows 7 x64 RC
Monitor
15.4"
Daney is online now   Reply With Quote
Old 10-12-09   #3 (permalink)
Mobo Master
 
Starbuck5000's Avatar
 
intel nvidia

Join Date: May 2008
Location: England
Posts: 1,031

Rep: 70 Starbuck5000 is acknowledged by some
Unique Rep: 63
Trader Rating: 4
Default

Quote:
Originally Posted by Daney View Post
= is used for writing
== is used for reading.

Change the = in the Else's/If's to == and it should be fine and dandy, good luck

Edit: You should also use "C" to check if it's C.
Cheers What do you meant by use "C"

Edit: Tried it and the red "squiggle" is only at the end of the Order == bit like its expecting a ;
My else's are still flagged with squiggles.

It says "Invalid expression term 'else'" and "; expected"
__________________
Electrical Engineering and Computer Science Student (Joint Bsc Hons)
STUDENT FINANCE HURRY UP!!!

Has far to many components for a 20 year old, and while you're at it forgive my spelling, the keyboard is dyslexic

Quote:
Originally Posted by Tator Tot View Post
Ah the dickery.

Sadly enough, I don't like being a dick in game. It's much more fun flaunting your junk IRL.

System: 24/7 rig, now with less powah than the bench
CPU
W3540
Motherboard
Evga X58 LE
Memory
3x2GB OCZ Golds
Graphics Card
Evga GTX295
Hard Drive
Perc 5i; 4 WDC3200AAKS's Raid 5, 1TB Caviar Green
Sound Card
Asus Xonar D2X
Power Supply
1000W Thermaltake modular
Case
Lian Li PC-A71
CPU cooling
EK-Supreme/BIX420
GPU cooling
EK full cover
OS
Windows 7 Pro - Retail MSDN-AA
Monitor
20.1" LG

Last edited by Starbuck5000 : 10-12-09 at 03:40 PM
Starbuck5000 is offline   Reply With Quote
Old 10-12-09   #4 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Also, you should be using 'else if's, not else's

Also, if you're checking for a string...ie. "C", you may need to use .equals("C") rather than ==.

example:

if c
do this

else if d
do this

else if e
do this

else
do this

That's extremely vague, but hopefully you get the idea.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen

Last edited by BiG O : 10-12-09 at 03:39 PM
BiG O is offline Overclocked Account   Reply With Quote
Old 10-12-09   #5 (permalink)
PC Gamer
 
Daney's Avatar
 
intel nvidia

Join Date: Apr 2009
Location: South-West, UK.
Posts: 1,233

Rep: 137 Daney is acknowledged by manyDaney is acknowledged by many
Unique Rep: 123
Trader Rating: 0
Default

Quote:
Originally Posted by BiG O View Post
Also, you should be using 'else if's, not else's

Also, if you're checking for a string...ie. "C", you may need to use .equals("C") rather than ==.

example:

if c
do this

else if d
do this

else if e
do this

else
do this

That's extremely vague, but hopefully you get the idea.
Wow, how did I forget that?

But yeah; he's right (Don't rep me for this btw )
__________________
Steam ID: prodaney
Epic thread

System: Acer Aspire 5633 WLMi
CPU
Intel Mobile Core 2 Duo T5500
Motherboard
Grapevine(Acer)
Memory
4GB (333MHz)
Graphics Card
nVidia GeForce 7300 Go
Hard Drive
160GB (SATA 150Gb/s)
Power Supply
N/A - Running off mains.
OS
Windows 7 x64 RC
Monitor
15.4"
Daney is online now   Reply With Quote
Old 10-12-09   #6 (permalink)
WaterCooler
 
killnine's Avatar
 
intel ati

Join Date: Aug 2005
Posts: 3,361

Rep: 161 killnine is acknowledged by manykillnine is acknowledged by many
Unique Rep: 144
FAQs Submitted: 1
Trader Rating: 9
Default

You will have to use character literals for what you are equating to your variable Order:

Quote:
if (Order == 'C')
{
//do something here
}
otherwise, right now you are saying "set the variable Order equal to the variable C", which you haven't declared.


Also, instead of hardcoding 'C', T, O, H in there, you can declare constants at the top of your file and change what character the user may put in down the road:


Quote:
CONST char COFFEE = 'C';
CONST char TEA = 'T';
CONST char ORANGE_JUICE = 'O';
CONST char HOT_CHOCOLATE = 'H';

.
.
.

if (Order == COFFEE)
{
//do something
}

System: Teh System
CPU
Intel i7 920 (3.2Ghz @ 1.0V)
Motherboard
Asus Rampage II Gene
Memory
6Gb Corsair XMS DDR3 (1333)
Graphics Card
VisionTek 4870
Hard Drive
Seagate 7200rpm (160)
Sound Card
X-fi Fatal1ty Pro
Power Supply
Silverstone Strider 750W
Case
Mini P180B
CPU cooling
OCZ Vendetta 2
GPU cooling
HR-03 GT
OS
Windows 7 (x64) RC1
Monitor
Dell 2001FP 20.1"
killnine is offline   Reply With Quote
Old 10-12-09   #7 (permalink)
AMD Overclocker
 
decompiled's Avatar
 
amd nvidia

Join Date: Feb 2006
Location: Redsox Nation
Posts: 704

Rep: 78 decompiled is acknowledged by some
Unique Rep: 68
Hardware Reviews: 9
Trader Rating: 0
Default

== checks if objects are equal. ObjectA == ObjectB. Do they use the same memory address.

.equals() for string values is checking to see if the characters match.

Finally as posted above. = is used for assignment.

System: Slow Poke
CPU
AMD X2 4400
Motherboard
MSI K8N Diamond +
Memory
3gb TCC5
Graphics Card
eVGA 7900GS
Hard Drive
74gb Raptor + Raid 1 640's
Sound Card
Audigy SE
Power Supply
OCZ 600 ModXstream
Case
Antec 1200
CPU cooling
Stock AMD
GPU cooling
Stock eVGA
OS
Windows 7 FTW Edition
Monitor
Dell 1905FP
decompiled is offline   Reply With Quote
Old 10-12-09   #8 (permalink)
.
 
BiG O's Avatar
 
intel nvidia

Join Date: Jul 2007
Location: Virginia
Posts: 3,589

Trader Rating: 4
Default

Quote:
Originally Posted by killnine View Post
You will have to use character literals for what you are equating to your variable Order:



otherwise, right now you are saying "set the variable Order equal to the variable C", which you haven't declared.


Also, instead of hardcoding 'C', T, O, H in there, you can declare constants at the top of your file and change what character the user may put in down the road:
He doesn't have to do that. He can just use .equals() to check the strings themselves.
__________________
Imaging with Windows PE
Please keep the OCN Terms of Service in mind when posting.

System: My System
CPU
Q6700
Motherboard
Gigabyte p35-DS4
Memory
8GB Crucial Ballistix DDR2-800 (4x2GB)
Graphics Card
BFG 8800GTS 512MB g92
Hard Drive
2X 500GB Seagate Barracuda 7,200 RPM SATA RAID 0
Sound Card
Razer Barracuda AC-1 7.1
Power Supply
ABS 700W Modular
Case
Antec 900
CPU cooling
Apogee GTZ
GPU cooling
Stock
OS
Vista Ultimate x64 SP1, Xubuntu 8.10, Windows 7
Monitor
Hanns-G 28" & Dell 19" widescreen
BiG O is offline Overclocked Account   Reply With Quote
Old 10-12-09   #9 (permalink)
Mobo Master
 
Starbuck5000's Avatar
 
intel nvidia

Join Date: May 2008
Location: England
Posts: 1,031

Rep: 70 Starbuck5000 is acknowledged by some
Unique Rep: 63
Trader Rating: 4
Default

Tried adding "else if" however its now saying that I have a "use of unassigned local variables"



Quote:
Originally Posted by killnine View Post
You will have to use character literals for what you are equating to your variable Order:



otherwise, right now you are saying "set the variable Order equal to the variable C", which you haven't declared.


Also, instead of hardcoding 'C', T, O, H in there, you can declare constants at the top of your file and change what character the user may put in down the road:

Like this

Attached Thumbnails
C# Doesn't like my Else's-more-else-problems.jpg   C# Doesn't like my Else's-ahhhhhhhh.jpg  
__________________
Electrical Engineering and Computer Science Student (Joint Bsc Hons)
STUDENT FINANCE HURRY UP!!!

Has far to many components for a 20 year old, and while you're at it forgive my spelling, the keyboard is dyslexic

Quote:
Originally Posted by Tator Tot View Post
Ah the dickery.

Sadly enough, I don't like being a dick in game. It's much more fun flaunting your junk IRL.

System: 24/7 rig, now with less powah than the bench
CPU
W3540
Motherboard
Evga X58 LE
Memory
3x2GB OCZ Golds
Graphics Card
Evga GTX295
Hard Drive
Perc 5i; 4 WDC3200AAKS's Raid 5, 1TB Caviar Green
Sound Card
Asus Xonar D2X
Power Supply
1000W Thermaltake modular
Case
Lian Li PC-A71
CPU cooling
EK-Supreme/BIX420
GPU cooling
EK full cover
OS
Windows 7 Pro - Retail MSDN-AA
Monitor
20.1" LG
Starbuck5000 is offline   Reply With Quote
Old 10-12-09   #10 (permalink)
nVidia Enthusiast
 
cathode's Avatar
 
intel nvidia

Join Date: Sep 2008
Location: USA
Posts: 363

Rep: 24 cathode is acknowledged by some
Unique Rep: 24
Trader Rating: 0
Default

no, declare the constants at the class level not in the method.

like this:
Code:
public class VendingMachine
{
  private const char COFFEE = 'C';
}
I'm not trying to sound condescending here but you should really invest some time in reading some beginner guides to C# because they go over all this kind of stuff.
__________________
System: New Rig!
CPU
Pentium D 920
Motherboard
ASUS P5K-E/WIFI-AP
Memory
4x1GB Crucial BallistiX
Graphics Card
BFG 8800 GTX OC
Hard Drive
3x WD Raptor 74GB (RAID-0)
Sound Card
Integrated
Power Supply
BFG 750W
Case
Cooler Master HAF 932
OS
Windows 7 Ultimate x64 (RTM)
Monitor
Gateway FHD2400 1920x1200 2ms
cathode is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools



All times are GMT -5. The time now is 10:47 AM.


Overclock.net is a Carbon Neutral Site Creative Commons License

Terms of Service / Forum Rules | Privacy Policy | DMCA Info | Advertising | Become an Official Vendor
Copyright © 2009 Shogun Interactive Development. Most rights reserved.
Page generated in 0.16738 seconds with 9 queries