ImageImageImage

OT: C# Homework Help

Moderators: bwgood77, Qwigglez, lilfishi22

User avatar
MrCheckOne2
Sophomore
Posts: 113
And1: 0
Joined: Aug 10, 2009
Location: Phoenix, AZ

OT: C# Homework Help 

Post#1 » by MrCheckOne2 » Fri Jan 28, 2011 4:58 am

Alright so I'm takin an intro course to C#
We did our Hello World program first and that was very simple and went by with no issues (I'm COMPLETELY new to programming...not a single clue or prior exposure to it)

Alright well I found out what my original problem was but now I have a question.

So I was declaring a constant as 9/5 thinking it would take whatever the value of that fraction was. I converted it to decimal instead and it's working fine, but now my question is, can I declare a constant in a way that I can enter a fraction and it'll use the value of it??
User avatar
MaryvalesFinest
Lead Assistant
Posts: 5,326
And1: 3
Joined: Jul 23, 2008
Location: Back

Re: OT: C# Homework Help 

Post#2 » by MaryvalesFinest » Fri Jan 28, 2011 5:53 am

I took a programming class my senior year in highschool, are they using that pink colored book still?
User avatar
MrCheckOne2
Sophomore
Posts: 113
And1: 0
Joined: Aug 10, 2009
Location: Phoenix, AZ

Re: OT: C# Homework Help 

Post#3 » by MrCheckOne2 » Fri Jan 28, 2011 6:01 am

I'm not attending your high school, wouldn't be able to tell you.
User avatar
MaryvalesFinest
Lead Assistant
Posts: 5,326
And1: 3
Joined: Jul 23, 2008
Location: Back

Re: OT: C# Homework Help 

Post#4 » by MaryvalesFinest » Fri Jan 28, 2011 6:02 am

No I took a computer programming when I was in highschool, was wondering if you are using the same book cause I might be able to help than.
User avatar
MrCheckOne2
Sophomore
Posts: 113
And1: 0
Joined: Aug 10, 2009
Location: Phoenix, AZ

Re: OT: C# Homework Help 

Post#5 » by MrCheckOne2 » Fri Jan 28, 2011 6:04 am

Nope, not a pink book.
User avatar
MaryvalesFinest
Lead Assistant
Posts: 5,326
And1: 3
Joined: Jul 23, 2008
Location: Back

Re: OT: C# Homework Help 

Post#6 » by MaryvalesFinest » Fri Jan 28, 2011 6:07 am

Ah alright, I'm not saying this is right cause that was like 4 years ago but if I remember I think constants were talked about at the start of course so that might work, you can always change the code back if it's wrong I think, good luck.
morol
Sophomore
Posts: 124
And1: 15
Joined: Mar 12, 2009

Re: OT: C# Homework Help 

Post#7 » by morol » Fri Jan 28, 2011 7:49 am

If you divide two integers using / operator it returns an integer, and 5 and 9 are both implicitly converted to int (in fact, they ARE ints, so there is no conversion afterall). If you want them to be treated as floats, You need to cast them:

float some_constant = (float) 9 / (float) 5

'/' operator, when given atl least one float (as above) returns a float. Give it a try,

Return to Phoenix Suns