### Thread: Exercize problem

1. No Profile Picture
G2k
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
2
Rep Power
0

#### Exercize problem

Hello all,
I recently bought a book on C# and I've been having a hard time with an exercize. This is what it asks:
Write and application that includes the logic from exercize 1, that obtains two numbers from the user and displays them, but rejects any input where both numbers are greater than 10 and asks for two new numbers.
Ok, so first of all, I have to do this in a Console Application. Second, the "Logic from exercize 1" means that basically I have to use two variables and with a boolean test, check whether my first or my second variable, but not both, is greater than 10.

This is what I have and I'm having a hard time fixing it:

Code:
```static void Main(string[] args)
{
beginning:
int var1, var2;
Console.WriteLine("Type your first number:");
var1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Type your second number:");
var2 = Convert.ToInt32(Console.ReadLine());

bool lessThan10;
lessThan10 = (var1 + var2) < 10;

if (lessThan10 = var1 ^ var2)
{
Console.WriteLine("Choose another 2 numbers plz:");
Console.WriteLine("\n");
goto beginning;
}

else
{
Console.WriteLine("{0} and {1} were the two numbers!", var1, var2);
}
}```
the problem is the if loops' test code. It tells me that it can't convert type 'int' to 'bool'...but how can I convert a number to a boolean? Any help please?
Thnx in advance
2. No Profile Picture
Nem
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
109
Rep Power
12
if (var1 + var 2 > 20)
{
Console.WriteLine("Choose another 2 numbers plz:");
Console.WriteLine("\n");
goto beginning;
}
else
{
Console.WriteLine("{0} and {1} were the two numbers!", var1, var2);
}
3. No Profile Picture
G2k
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
2
Rep Power
0
hm....I think that the exercize wants me to use a logical XOR....? isn't that strictly for booleans? Cus the question is "but rejects any input where both numbers are greater than 10 and asks for two new numbers" :confused: and it says that I have to use the same logic as in ex. 1, which says "if we have two integers stored in variables var1 and var2, what boolean test can we perform to see if one or the other (but not both) is greater than 10?"
I'm posting my questins for the exercizes here because the book i have used to supply answers but no longer does for some stupid reason (a server crashed or something)....its a wrox book. I dont suggest it to anyone, not because the lessons are bad, actually they're pretty good, but there are no answers!
thank you for your help
Last edited by G2k; June 29th, 2003 at 02:13 PM.
4. No Profile Picture
Nem
Contributing User
Devshed Newbie (0 - 499 posts)

Join Date
Jun 2003
Posts
109
Rep Power
12
(var1 > 10 ^ var2 > 10) || (var1 <= 10 & var2 <= 10)

True if var1 > 10 and var2 isn't or var2 > 10 and var1 isn't or both are smaller or equal to 10.
5. No Profile Picture
Junior Member
Devshed Newbie (0 - 499 posts)

Join Date
Jul 2003
Location
Canada
Posts
1
Rep Power
0
Just a comment, i don't mean to be picky, but "if" is a statement not a loop. There is not way to iterate with an if statement, only a a while, do..while, or for. Sorry, i just had to make that clear.