d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > It's Finals Week In My C# Class
Prev123
Add Reply New Topic New Poll
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Dec 19 2013 08:35am
You're really struggling, aren't you?

It's
Code
else if
, not
Code
if else


If you want a bigger or equal b, you don't write
Code
a ==> b
, but
Code
a >= b


Your assignments are full of fail too. The variable you assign to needs to be on the left hand side.
Wrong
Code
sales * 1.03 = total;

you're trying assign to a value. You might as well try to say 1=2 and from now on 1*1 equals 4
Correct(er):
Code
total = sales*1.03;

But it won't work, because sales and total are decimals and 1.03 is a double. You can't mix those without a cast and ideally you should simply use a decimal literal instead:
Code
total = sales*1.03m;


This post was edited by KrzaQ2 on Dec 19 2013 08:35am
Member
Posts: 22,329
Joined: Jul 2 2008
Gold: 450.00
Dec 19 2013 03:22pm
Quote (KrzaQ2 @ Dec 19 2013 08:35am)
You're really struggling, aren't you?

It's
Code
else if
, not
Code
if else


If you want a bigger or equal b, you don't write
Code
a ==> b
, but
Code
a >= b


Your assignments are full of fail too. The variable you assign to needs to be on the left hand side.
Wrong
Code
sales * 1.03 = total;

you're trying assign to a value. You might as well try to say 1=2 and from now on 1*1 equals 4
Correct(er):
Code
total = sales*1.03;

But it won't work, because sales and total are decimals and 1.03 is a double. You can't mix those without a cast and ideally you should simply use a decimal literal instead:
Code
total = sales*1.03m;



Yes i am really struggling, hence the asking for help part. But i do appreciate the fixes you gave me, although im curious what the "m" does to fix the solution. I did it, and theres no longer a squiggly line under it, but i dont know why.

infact everything works except theres a squiggly under the underlined portion now:

-----------

{
decimal sales, total, profit;
Console.WriteLine("Enter Sales Amount: ");
sales = decimal.Parse(Console.ReadLine());
{

if (sales >= 1000) total = sales*1.03m;

if (sales >= 1000.1 ||<= 5000) total = sales*1.035m;

if (sales >= 5000.1 || <= 10000) total = sales*1.04m;

if(sales >= 10000.1) total = sales*1.045m;

}

profit = remainder - sales;
Console.WriteLine("The Companies Total Profits were: $" );
Console.ReadKey();

}

--------------

cant figure out what im doing wrong on the other side of the statement. Also i removed the "else" entirely because no matter what side it was on, it was red squigglied.

p.s. Thank you for your help sir, i do appreciate it.

This post was edited by Hockeygod9911 on Dec 19 2013 03:22pm
Member
Posts: 32,925
Joined: Jul 23 2006
Gold: 3,804.50
Dec 19 2013 03:27pm
Quote (Hockeygod9911 @ Dec 19 2013 04:22pm)
im curious what the "m" does to fix the solution. I did it, and theres no longer a squiggly line under it, but i dont know why.


http://msdn.microsoft.com/en-us/library/364x0z75.aspx


Quote
if (sales >= 1000) total = sales*1.03m;
             
                if (sales >= 1000.1 ||<= 5000) total = sales*1.035m;

                if (sales >= 5000.1 || <= 10000) total = sales*1.04m;

.

both sides of || must evaluate to a boolean.

<= 5000

does not evaluate to a boolean

This post was edited by carteblanche on Dec 19 2013 03:28pm
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Dec 19 2013 03:45pm
Oh, yeah, I missed that.

Code
if (sales >= 1000) total = sales*1.03m;

else if (sales >= 1000.1 || sales <= 5000) total = sales*1.035m;

else if (sales >= 5000.1 || sales <= 10000) total = sales*1.04m;

else if(sales >= 10000.1) total = sales*1.045m;
Member
Posts: 8,154
Joined: Mar 28 2010
Gold: 23.70
Dec 27 2013 06:42pm
Quote (KrzaQ2 @ Dec 19 2013 05:45pm)
Oh, yeah, I missed that.

Code
if (sales >= 1000) total = sales*1.03m;

else if (sales >= 1000.1 || sales <= 5000) total = sales*1.035m;

else if (sales >= 5000.1 || sales <= 10000) total = sales*1.04m;

else  if(sales >= 10000.1) total = sales*1.045m;


Check your work, I can already tell you never go into your else if statements.

You do know || is an OR type statement, and not an AND type statement?
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Dec 28 2013 05:54am
I didn't bother to correct the logic - I only made the syntax work.
Member
Posts: 473
Joined: Sep 10 2013
Gold: 150.01
Feb 13 2014 02:28pm
kzra worst programmer NA , please dont listen to his misguiding advice
Member
Posts: 1,995
Joined: Jun 28 2006
Gold: 7.41
Feb 13 2014 02:49pm
Quote (mbonellZ @ Feb 13 2014 03:28pm)
kzra worst programmer NA , please dont listen to his misguiding advice


Lol? Where did that come from?
Member
Posts: 13,425
Joined: Sep 29 2007
Gold: 0.00
Warn: 20%
Feb 13 2014 09:25pm
Quote (mbonellZ @ Feb 13 2014 04:28pm)
kzra worst programmer NA , please dont listen to his misguiding advice


Grats, on reviving a topic that was made before Christmas of last year.
Member
Posts: 9,803
Joined: Jun 28 2005
Gold: 6.67
Feb 14 2014 07:19am
Did he mean me but failed to spell my nick properly?
Go Back To Programming & Development Topic List
Prev123
Add Reply New Topic New Poll