 |
BOOK: Beginning Visual C#  | This is the forum to discuss the Wrox book Beginning Visual C#, Revised Edition of Beginning C# for .NET v1.0 by Karli Watson, David Espinosa, Zach Greenvoss, Jacob Hammer Pedersen, Christian Nagel, Jon D. Reid, Matthew Reynolds, Morgan Skinner, Eric White; ISBN: 9780764543821 |
|
Welcome to the p2p.wrox.com Forums.
You are currently viewing the BOOK: Beginning Visual C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 29th, 2003, 06:40 AM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Chapter 4 exercize questions
Hello all,
since the answeres are nowhere else to be found, I'll just ask all my questions here for exercize solutions.
For ex. 2, this is what I have and I'm having a hard time fixing it:
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
|
|

July 21st, 2003, 11:05 AM
|
|
Authorized User
|
|
Join Date: Jun 2003
Posts: 50
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
After analysing the code in detail, I have found there are serious flaws in
the code. What this code is trying to achieve is to post the data to a
different page while using the server ASP.NET web form controls by defining
the "runat=server" in the form tag.
If we are using this attribute with the form tag, the values of form will
always be posted to the same page, you can check it by changing the
"method=post" to "method=get". There is no use of "action" attribute while
using the "runat=server" attribute with the form tag. If you need to post
the data to a different page by using the "request.form" or
"request.querystring" collection, you need to use HTML controls in ASP.NET.
|
|

July 29th, 2003, 06:28 PM
|
|
Registered User
|
|
Join Date: Jul 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi:
This is my answer.
static void Main(string[] args)
{
AskForNumbers:
Console.WriteLine("Enter the first number:");
int myInt1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter the second number:");
int myInt2 = Convert.ToInt32(Console.ReadLine());
if ((myInt1 > 10) && (myInt2 > 10))
{
Console.WriteLine("I'm sorry, you have to re-enter the numbers
again.");
goto AskForNumbers;
}
Console.WriteLine("Integers less than 10? {0}", (myInt1 < 10&&
(myInt2 < 10));
Console.WriteLine("Integers between 0 and 5? {0}, {1}", (0 <=
myInt1) && (myInt1 <= 5),(0 <= myInt2) && (myInt2
<=5));
}
It just works fine.
|
|

November 14th, 2003, 04:29 PM
|
|
Registered User
|
|
Join Date: Oct 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Here is what I have. It works fine.
{
start:
Console.WriteLine("One number must be less than 10");
Console.WriteLine("Please enter a number:");
int firstNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Please enter a second number:");
int secondNumber = Convert.ToInt32(Console.ReadLine());
if (firstNumber <= 10 || secondNumber <= 10)
{
Console.WriteLine("The two numbers you entered are: {0} and {1}",
firstNumber, secondNumber);
}
else
{
Console.WriteLine("One of the numbers must be less than 10. Try again");
goto start;
}
|
|

November 16th, 2003, 01:57 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
bool test = true;
int firstNumber = 0; int secondNumber;
do
{
Console.WriteLine("One number must be less than 10, AIGHT!?!?");
Console.WriteLine("Enter a number:");
firstNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Enter a second number:");
secondNumber = Convert.ToInt32(Console.ReadLine());
if (firstNumber <= 10 || secondNumber <= 10)
{
Console.WriteLine("You entered: {0} and {1}",
firstNumber, secondNumber);
Console.WriteLine("\nGOOD JOB!!!");
test = true;
}
else
{
Console.WriteLine("Try again stupid!");
test = false;
}
}
while( test == false );
}
}
Thx
Nigeeeeeeeeee
|
|

November 30th, 2003, 10:54 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Another attempt...
static void Main(string[] args)
{
start:
Console.WriteLine("Enter an integer");
int myInt1 = Convert.ToInt32 (Console.ReadLine());
Console.WriteLine("Enter a second Integer");
int myInt2 = Convert.ToInt32 (Console.ReadLine());
if ((myInt1 < 10) || (myInt2 < 10))
{
Console.WriteLine("First integer less than 10? {0}\nSecond integer less than 10? {1}",
myInt1 < 10, myInt2 < 10);
Console.WriteLine("Integer between 0 and 5? First Number {0} and Second Number {1}",
(0<=myInt1) && (myInt1 <= 5), (0<=myInt2) && (myInt2 <=5));
Console.WriteLine("Bitwise AND of First Integer and 10 = {0}\nSecond Integer and 10 = {1}",
myInt1 & 10, myInt2 & 10);
}
else
{
Console.WriteLine("You must enter one integer value that is less than 10!");
Console.WriteLine("\nTry Again.");
goto start;
}
}
}
}
|
|

February 26th, 2004, 11:37 PM
|
|
Registered User
|
|
Join Date: Feb 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
don't use 'goto' better!
int var1,var2;
bool firstBool,secondBool;
do
{
Console.WriteLine("Please enter first number:");
var1 = Convert.ToInt32(Console.ReadLine());
if (var1 > 10)
{
Console.WriteLine("Please enter a less than 10's integer number!");
firstBool = false;
}
else
{
firstBool = true;
}
}
while (firstBool == false);
do
{
Console.WriteLine("Please enter second number:");
var2 = Convert.ToInt32(Console.ReadLine());
if (var2 > 10)
{
Console.WriteLine("Please enter a less than 10's integer number!");
secondBool = false;
}
else
{
secondBool = true;
}
}
while (secondBool == false);
Console.WriteLine("{0} {1}",var1,var2);
|
|

March 5th, 2004, 06:40 PM
|
|
Registered User
|
|
Join Date: Mar 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
May as well throw my 2 cents in on this:
static void Main(string[] args)
{
int myInt = 0, myInt2 = 0;
while (myInt < 10 || myInt2 < 10)
{
Console.Write("Enter an integer: ");
myInt = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter a second integer: ");
myInt2 = Convert.ToInt32(Console.ReadLine());
if (myInt > 10 && myInt2 > 10)
{
Console.WriteLine("\nOne integer must be less than or equal to 10" +
"\nPlease enter 2 new numbers.");
myInt = 0;
continue;
}
else
{
Console.WriteLine("\nInteger1 less than 10? {0}", myInt < 10);
Console.WriteLine("Integer1 between 0 and 5, inclusive? {0}",
(0 <= myInt) && (myInt <= 5));
Console.WriteLine("Bitwise AND of Integer1 and 10 = {0}\n", myInt & 10);
Console.WriteLine("Integer2 less than 10? {0}", myInt2 < 10);
Console.WriteLine("Integer2 between 0 and 5, inclusive? {0}",
(0 <= myInt) && (myInt2 <= 5));
Console.WriteLine("Bitwise AND of Integer2 and 10 = {0}", myInt2 & 10);
break;
}
}
}
|
Similar Threads
|
| Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Chapter 1 - Two questions |
mikener |
BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 |
6 |
March 17th, 2008 03:59 PM |
| Two Chapter 3 Questions |
psychonet |
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 |
6 |
April 13th, 2007 11:39 PM |
| Comments and Questions for Chapter 2 |
nguyendh |
BOOK: Ivor Horton's Beginning Visual C++ 2005 |
0 |
June 24th, 2006 07:16 PM |
|
 |