Forums: » Register « |  Free Tools |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |

New Free Tools on Dev Shed!

#1
June 29th, 2003, 08:32 AM
 G2k
Junior Member

Join Date: Jun 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation 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:
Quote:
 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;

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?

#2
June 29th, 2003, 02:35 PM
 Nem
Contributing User

Join Date: Jun 2003
Posts: 109
Time spent in forums: < 1 sec
Reputation Power: 11
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
June 29th, 2003, 03:09 PM
 G2k
Junior Member

Join Date: Jun 2003
Posts: 2
Time spent in forums: < 1 sec
Reputation 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" 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!

Last edited by G2k : June 29th, 2003 at 03:13 PM.

#4
June 30th, 2003, 01:50 PM
 Nem
Contributing User

Join Date: Jun 2003
Posts: 109
Time spent in forums: < 1 sec
Reputation Power: 11
(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
July 8th, 2003, 10:42 AM
 Er3s
Junior Member

Join Date: Jul 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation 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.

 Viewing: Dev Shed Forums > Programming Languages > C Programming > Exercize problem