954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Simple C# Programming doubt (Beginner)

I am building a program with Name, Roll No., Marks in different subjects, Total and Average. Just wanted some advice. Pls encourage me.


class Report


{
static void Main ()

{

string s = " ";
int a;
/*,c,d,e,f,g,h,i;*/

Console.WriteLine ("Enter the Name:");
s= Console.ReadLine ();

Console.WriteLine ("Enter the Roll No.:");
a=Convert.ToInt32(Console.ReadLine ());

/*
Marks in English:\nMarks In Hindi:\nMarks in Maths:\nMarks in Social:\nMarks in G.K.:\n");

b=Convert.ToInt32(Console.ReadLine ());
c=Convert.ToInt32(Console.ReadLine ());
d=Convert.ToInt32(Console.ReadLine ());
e=Convert.ToInt32(Console.ReadLine ());
f=Convert.ToInt32(Console.ReadLine ());
g=Convert.ToInt32(Console.ReadLine ());
h=Convert.ToInt32(Console.ReadLine ());
i=Convert.ToInt32(Console.ReadLine ());*/

}

}

When I am asked to enter name it is not coming on the side ways

it is coming like this

Enter the Name:
Jonah


I want it to come in this way

Enter the Name: Jonah


please help what I must do to make my input name to be typed just beside " Enter the Name:" instead of next line.

thanks

jonahmano
Newbie Poster
3 posts since Oct 2009
Reputation Points: 16
Solved Threads: 0
 

Hi Jonahmano! This can be done very easy.
Instead of WriteLine, use Write.
WriteLine writes a string and put a extra carriage return character after, Write does not.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

ddanbe you are wrong.

I tried to change WriteLine with Write and I got a bunch of errors

My code is working so please makes changes in my code and paste it back.

Let me compile and see

thanks

jonahmano
Newbie Poster
3 posts since Oct 2009
Reputation Points: 16
Solved Threads: 0
 

No, ddanbe is correct. If you use Console.Write() then read the line it will not advance the cursor to the next line. You probably made modifications to the wrong section of the code. Here are the lines in question:

Console.WriteLine ("Enter the Name:");
Console.WriteLine ("Enter the Roll No.:");


Change those to Console.Write(); and please be careful when telling ddanbe when is wrong. He usually isn't.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

Also notice you don't have an extra Console.ReadKey() or ReadLine() as a last statement to keep the console on the screen. Use code tags when you post code, just as sknake did.

ddanbe
Senior Poster
3,829 posts since Oct 2008
Reputation Points: 2,070
Solved Threads: 661
 

@jonahmano: ddanbe you are wrong.
No. He gave you a solution. Use Write Method.

Console.Write("Enter Name : ");
value=Console.ReadLine();
__avd
Posting Genius (adatapost)
Moderator
8,648 posts since Oct 2008
Reputation Points: 2,136
Solved Threads: 1,241
 

Thanks a lot for all your help

jonahmano
Newbie Poster
3 posts since Oct 2009
Reputation Points: 16
Solved Threads: 0
 

Please mark this thread as solved as danny provided a solution to your question and good luck!

If you are still having issues please post back on this thread and we will be more than happy to help you.

sknake
Industrious Poster
4,954 posts since Feb 2009
Reputation Points: 1,764
Solved Threads: 735
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: