TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Joseph
NA
14
17.6k
for loops
Apr 6 2011 8:38 PM
Instruction:
Input a string from the user. The program will check to ensure that the string
has a length in the range of 2 to 10 characters (inclusive). If the user entered an
incorrect string, error messages for each error will be displayed(example below)
specifying the type of error, and a loop will be used to input a new string.
must use a for loop to do this.
Output should be.
Stringy
Enter a string: a
Error, the string is too short.
Enter a string: 123456789abc
Error, the string is too long.
Enter a string: ok string
o
k
s
t
r
i
n
g
Press any key to exit:
For program, i know how to use it a foreach loop
but that in a for loop and i don't know how to put a limit range in a string.
My code is:
static void Main(string[] args)
{
string sName;
Console.Title = "Stringy";
Console.WriteLine("{0, 40}", "Stringy");
Console.Write("Enter a string: ");
sName = Console.ReadLine();
foreach (char cValue in sName)
{
Console.WriteLine(cValue);
}
Console.WriteLine("Press any key to exit");
Console.ReadLine();
}
Reply
Answers (
1
)
Confused - unasigned variable
VS Debugger Broke