0
C# Beginner question
Hello, I was working on my C# exercises today and am stuck on this one. What am I missing here? I've been staring at it trying to figure it out. It should say; "Hello, name of person". I really appreciate your help. Thank you. using System; class MainClass { public static void Main (string[] args) { Console.WriteLine("What is your name?"); var v1 = Console.ReadLine(); Console.WriteLine ("Hello, v1"); } }
4 Answers
+ 6
The mistake you've made was embedding the variable v1 in the string output.
In this case, we are going to print the value of v1 instead of the string "v1".
There are various ways to achieve this:-
https://code.sololearn.com/chzNBRsLf4aE/?ref=app
Feel free to pick one that you find easiest to understand! đ
+ 3
Hello there, your code is almost correct except for the last line.
it should be
Console.WriteLine("Hello {0}",v1);
during runtime, the {0} will be replaced by value of v1
+ 2
Hello again, this time you've made some mistakes with code brackets. look carefully
if(v1 == "yes"){....} //you missed the end bracket here.
if(V2 == "maybe"){....} //you missed the body start bracket for this if statement
and similarly you've missed many brackets. so please check that each starting bracket has its own end bracket
0
I'm coming a long way guys! I've been doing a ton of exercises today. Here's another one I'm stuck on and have tried changing it up. Maybe is the new option and if it is inputted it should state; "keep practicing". However, when you type in maybe it doesn't proceed to "Keep practicing". Any suggestions?
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine("Do you like programming?");
var v1 = Console.ReadLine();
if (v1 == "yes") {
Console.WriteLine("Good! Me too!");
if (v1 == "maybe")
Console.WriteLine("Keep practicing!");
}
if (v1 == "no") {
Console.WriteLine("That's a shame. It's fun!");
}