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
owain harris
NA
1
0
Char and int help
Aug 20 2009 8:02 AM
Can any one help me? I am new to programming..
I am creating a console output to let a user enter a series of random numbers. The letters 'n' or 'N' will break the loop, and display the sum and average.
I can do most of this, execpt the only part confusing me is converting the char to an int, as entering a 'n' or 'N', will break it, as it is an int.
here is my code so far:
class MyClass
{
static void Main(string[] args)
{
int num = 0;
int i = - 1;
int sum = 0;
int avg = 0;
do
{
Console.WriteLine("Enter N to quit");
num = char.Parse(Console.ReadLine());
i++;
if (num == 'n')
{
break;
}
else
{
sum = sum + num;
}
} while (num != 'n' || num != 'N');
avg = sum / i;
Console.WriteLine("\nThe amount of numbers entered was: " + i);
Console.WriteLine("\nSum is " + sum);
Console.WriteLine("\naverage is " + avg);
Console.WriteLine("\nProgram Finsihed");
Console.WriteLine("Press any key to continue...");
Console.ReadLine();
Reply
Answers (
2
)
data transfer from excel to oracle
How can check invisible nick Yahoo?