Reputation: 71
I want my program to write the following to to the console:
The volume of your Right Rectangular Prism is: * Cm^3
But I don't know how to make it write anything after I specify the "& volume" in the call to the WriteLine
method. Is there any way to actually do this?
Here is my code for that line:
Console.Write("The volume of your right rectangular prism is: " & volume):("Cm^3")
Upvotes: 4
Views: 819
Reputation: 61
Looks like a line of C#?
You can use something like:
Console.Write("The volume of your right rectangular prism is: ");
Console.WriteLine(volume & " Cm^3");
Upvotes: 3
Reputation: 43743
The syntax of your code is invalid. The following portion is wrong:
volume):("Cm^3")
The first closing parentheses ends the call to the Write
method. The colon is used in VB.NET to separate two statements on the same line, much like the semicolon is used in C#, and other similar languages. However, the next statement, after the colon, is invalid. ("Cm^3")
is, all on its own, an invalid statement. It looks like you are specifying parameters to a method without ever specifying which method you are trying to call. I suspect that what you meant to do was something like this:
Console.Write("The volume of your right rectangular prism is: " & volume) : Console.Write("Cm^3")
That will work, but it's a bit unusual. Typically, in VB.NET, you'd just put each statement on its own line, like this:
Console.Write("The volume of your right rectangular prism is: " & volume)
Console.Write("Cm^3")
However, rather than using concatenation, at that point, you could just call Write
three times, like this:
Console.Write("The volume of your right rectangular prism is: ")
Console.Write(volume)
Console.Write("Cm^3")
Or, you could concatenate all three together in a single call to the Write
method, like this:
Console.Write("The volume of your right rectangular prism is: " & volume & "Cm^3")
Or, another popular option is to use the string formatting feature like this:
Console.Write("The volume of your right rectangular prism is: {0}Cm^3", volume)
Upvotes: 0
Reputation: 3834
Try it this way:
Console.Write("The volume of your right rectangular prism is: " & volume & " whatever else you want to say")
In fact you could keep going... the basic concept is end your text then do a &
, then add the variable. If you need more you can always repeat it the same way.
Upvotes: 2
Reputation: 8982
I like to use String.Format for things like this:
String.Format("The volume of the sphere with radius {0} is {1}", radius, volume)
You can put this inside your Console.WriteLine
, or save it to another variable first if you want to keep the line from getting too long.
Upvotes: 2