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
Henry Lhteenmaki
NA
13
12.3k
How to handel error
Dec 21 2011 1:41 PM
Hi !
in this particular program I want to stop program for executing the rest of instruction until the error detected by error handler is solved, I try to use return key work , but it did not work for this purpose .
I enter a string value instead a integer , and instead the program force me the correct the input error it ask me to enter the second score even the first one was not correct .
Br
Henry
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Assignment3
{
class Program
{
static void Main(string[] args)
{
string name, message = " ";
int average = 0 ;
//Users names
Console.WriteLine("Enter you name");
name = Console.ReadLine();
// Declare variables the type array
string[] var = { "first", "second", "third" };
int[] scores = new int[3];
// loop trought the arrays
for (int i = 0; i < var.Length; i++)
try
{
Console.WriteLine("Enter your {0}, score", var[i]);
scores[i] = int.Parse(Console.ReadLine());
average += scores[i]/3;
}
catch (FormatException) {
Console.WriteLine("the {0}, is Not a numeric value ", scores[i]);
}
}
// Testing the average
if (average >= 90 && average <= 100)
{
message = "Wow, you did great";
}
else if (average >= 80 && average <= 89)
{
message = "Pretty good!";
}
else if (average >= 75 && average <= 79)
{
message = "That was close....";
}
else if (average < 75)
{
message = "Better luck next time";
}
Console.WriteLine("Hi {0}, {1}", name, message);
Console.ReadLine();
return;
}
}
}
Reply
Answers (
1
)
indexOutOfRangeExeption was unhadled error
Question - how to hide some data after build