944,161 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 720
  • C# RSS
Oct 16th, 2009
-2

Simple C# Programming doubt (Beginner)

Expand Post »
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
Similar Threads
Reputation Points: 16
Solved Threads: 0
Newbie Poster
jonahmano is offline Offline
3 posts
since Oct 2009
Oct 16th, 2009
3
Re: Simple C# Programming doubt (Beginner)
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.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Oct 16th, 2009
-2
Re: Simple C# Programming doubt (Beginner)
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
Reputation Points: 16
Solved Threads: 0
Newbie Poster
jonahmano is offline Offline
3 posts
since Oct 2009
Oct 16th, 2009
3
Re: Simple C# Programming doubt (Beginner)
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:
C# Syntax (Toggle Plain Text)
  1. Console.WriteLine ("Enter the Name:");
  2. 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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Oct 16th, 2009
0
Re: Simple C# Programming doubt (Beginner)
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.
Reputation Points: 2035
Solved Threads: 645
Senior Poster
ddanbe is offline Offline
3,740 posts
since Oct 2008
Oct 16th, 2009
0
Re: Simple C# Programming doubt (Beginner)
@jonahmano: ddanbe you are wrong.
No. He gave you a solution. Use Write Method.
C# Syntax (Toggle Plain Text)
  1. Console.Write("Enter Name : ");
  2. value=Console.ReadLine();
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Oct 16th, 2009
0
Re: Simple C# Programming doubt (Beginner)
Thanks a lot for all your help
Reputation Points: 16
Solved Threads: 0
Newbie Poster
jonahmano is offline Offline
3 posts
since Oct 2009
Oct 16th, 2009
0
Re: Simple C# Programming doubt (Beginner)
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.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: A tcp ip client using C#
Next Thread in C# Forum Timeline: Maintaining sync between two dropdownlists





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC