 |
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
|
|
|
|

November 9th, 2003, 02:06 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Statement not working?
Hello,
Code works fine. But i was just wondering why the last line of code won't run. (commented line). I Can 't figure it out. Maybe something to do with type conversion? I have no clue, so i have decided to ask the pros :)
Here's the code:
static void Main(string[] args)
{
int firstNumber = 0, secondNumber = 0, thirdNumber = 0, fourthNumber = 0, tmp = 0;
Console.WriteLine( "Enter a number: \n1:");
firstNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine( "\n2:");
secondNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine( "\n3:");
thirdNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine( "\n4:");
fourthNumber = Convert.ToInt32(Console.ReadLine());
Console.WriteLine( "You entered: {0}, {1}, {2}, {3}", firstNumber, secondNumber, thirdNumber, fourthNumber );
Console.WriteLine( "The product of: {0} * {1} * {2} * {3} = {4}", firstNumber, secondNumber, thirdNumber, fourthNumber, firstNumber * secondNumber * thirdNumber * fourthNumber );
//Console.WriteLine( "{0} * {2} = {3}", firstNumber, secondNumber, firstNumber * secondNumber);
This is the line of code i don't understand why it won't execute:
//Console.WriteLine( "{0} * {2} = {3}", firstNumber, secondNumber, firstNumber * secondNumber);
Thx
Nigeeeeeeeeee
|
|

November 9th, 2003, 03:21 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Take a look at this:
Console.WriteLine( "{0} * {2} = {3}", firstNumber, secondNumber, firstNumber * secondNumber);
As you can see, you have added the parameters for 0, 2 and 3, but you're only supplying three parameters in the list of your output. The numbers you're putting between {} should have a matching parameter. In this case, the highest number is 3 (zero based), so you should pass 4 parameters you want to write to the console. I think this is what you're after:
Console.WriteLine( "{0} * {1} = {2}", firstNumber, secondNumber, firstNumber * secondNumber);
Cheers,
Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
|
|

November 9th, 2003, 04:25 PM
|
|
Registered User
|
|
Join Date: Nov 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
LOL such a stupid mistake!! :D
THANKS IMAR!!!!
Thx
Nigeeeeeeeeee
|
|

November 9th, 2003, 08:09 PM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
"tmp=0"ÃÃÃâÃïÃÃÃöòôÃõÃÃÃ.à ªÃ²Ã´ÃõÃû´ÃôµÃ´úÃë²»Ãà ÃÃÃÃ,¶øÃâ´ÃµÃô¿ÃÃÃ,ý´Ãµà ´úÃëÃÃÃà õð¡???????
|
|

November 9th, 2003, 08:16 PM
|
|
Registered User
|
|
Join Date: Sep 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Ã
¶,I see!!!ÃÃÃâ³öÃÃÃÃÃæÃâÃôúÃëÃà ÃÃ:
Console.WriteLine("The product of {0} {1} {2} and {3} is (4)}." ,
firstNumber,
secondNumber, thirdNumber, fourthNumber, firstNumber * secondNumber * thirdNumber * fourthNumber);
ÃòêÃÃÃÃûÃùÃ÷ÃÃÃøö±äÿ, ¶Ã¸(4)¾ÃÃÃû¸ö²»ºÃᬵñäÿ,¶à Ãð!
|
|
 |