Code problem.
Page 1 of 1
Rayne01




Posts: 39

PostPosted: Wed, 25th Sep 2013 01:02    Post subject: Code problem.
I mentioned in a previous thread Iv'e just started C# programming, for some reason, a piece of code I'm using isn't working, but it looks correct to me, any insight would be grateful, using Visual Studios 2010, the code is;

if (u > = 21)
{
Console.Write("stuff");
}

Error list is saying "invalid expression term '='

if (u = > 21)
{
Console.Write("My stuff");
}

That gives me the "Invalid expression term '>'
Back to top
Interinactive
VIP Member



Posts: 29151

PostPosted: Wed, 25th Sep 2013 01:06    Post subject:
⁢⁢


Last edited by Interinactive on Tue, 5th Oct 2021 02:59; edited 1 time in total
Back to top
Nalo
nothing



Posts: 13438

PostPosted: Wed, 25th Sep 2013 01:08    Post subject:
⁢⁢


Last edited by Nalo on Wed, 3rd Jul 2024 06:24; edited 2 times in total
Back to top
Rayne01




Posts: 39

PostPosted: Wed, 25th Sep 2013 01:11    Post subject:
Firstly, it had to be typed with the > first, as i realized the other way around assigns 'u' and it's already declared, second, that one space between the '>' and the '='' presents errors.

That one space between the operators screws the code, i didn't know that as i assumed like C++ it classes it as just white space, apparently not.

Thank you so much, that has been annoying me and pissing me off for about an hour, just trying to decipher what the hell was wrong.
Back to top
Rayne01




Posts: 39

PostPosted: Wed, 25th Sep 2013 01:14    Post subject:
Yeah, that one space caused an ungodly amount of confusion and error that i just couldn't get passed, now my code goes off without problem, I'll paste the code so you can see what I mean.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Alcohol_Male_Female
{
class Program

{
static void Main(string[] args)
{
string input;
int u;
int dayCount = 0;
int total;
string inNumber;

do
{
Console.Write("How many units of alcohol do you consume daily? : ");
inNumber = Console.ReadLine();
u = Convert.ToInt32(inNumber);
dayCount++;

if (u >= 21)
{
Console.Write("Male - exceeded weekly units\n");
}

total = dayCount + 0;

}while (dayCount != 7);
}

}
}
Back to top
[mrt]
[Admin] Code Monkey



Posts: 1338

PostPosted: Sun, 1st Dec 2013 14:37    Post subject:
Nalo wrote:
Yeah remove the space. EVen a dummy like me can help sometimes lol wut


lol that made my day

I'm proud of you Nalos Very Happy


teey
Back to top
Page 1 of 1 All times are GMT + 1 Hour
NFOHump.com Forum Index - Programmers Corner
Signature/Avatar nuking: none (can be changed in your profile)  


Display posts from previous:   

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB 2.0.8 © 2001, 2002 phpBB Group