Reputation: 23
{
int x;
x = 2;
Console.WriteLine("Hi, Please select any number from 1,2,3,4");
string userValue;
userValue = Console.ReadLine();
Console.WriteLine ("You selected: " + userValue + x);
Console.ReadLine();
}
I want value of x to be add when I select anyone from above numbers e.g. If I select 1 then value of x=2 should be add and answer should be "3"
Where is mistake as am not putting an integer into a bucket.
Upvotes: 0
Views: 45
Reputation: 23
{
int x;
x = 2;
Console.WriteLine("Hi, Please select any number from 1,2,3,4");
int userValue = Convert.ToInt32(Console.ReadLine());
Console.WriteLine ("You selected: " + (userValue + x));
Console.ReadLine();
}
That Worked! :)
Upvotes: 0
Reputation: 9881
I see two problems here: 1) userValue is a string, 2) you lack parentheses in your WriteLine. Have you tried something like :
int userValue = Convert.ToInt32(Console.ReadLine());
// ....
Console.WriteLine ("You selected: " + (userValue + x));
Upvotes: 1