Click here to Skip to main content
15,917,731 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Write an application that asks a user to enter an IQ score. If the score is a number less than 0 or greater than 200, issue an error message; otherwise, issue an “above average”, “average”, or “below average” message for scores over, at, or under 100, respectively.

What I have tried:

C#
using System;

namespace Question_5
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("What is your IQ score");
            int IQScore = Convert.ToInt32(Console.ReadLine());

            if (IQScore < 0) || (IQScore > 200)
            {
                throw new InputException(string.Format("IQScore is out of range: score should range from 0 to 200"));
            }
         else if (IQScore < 100)
            {
                Console.WriteLine("IQScore is average");
            }
            else
            {
                Console.WriteLine("IQCore is above average");
            }
            Console.ReadKey();
        }
    }
}
Posted
Updated 4-Feb-22 8:57am
v3
Comments
Dave Kreskowiak 4-Feb-22 13:17pm    
...and you had a question you forgot to ask?
Patrice T 4-Feb-22 13:37pm    
And the question is ...

1 solution

In your program, you are missing the parenthesis with if clause. Use the correct Exception class, Correct your code accordingly:
if ((IQScore < 0) || (IQScore > 200))
{
      throw new Exception(string.Format("IQScore is out of range: score should range from 0 to 200"));
}
 
Share this answer
 
Comments
Jay Katariya 4-Feb-22 13:59pm    
Superb thank you sir
M Imran Ansari 4-Feb-22 14:07pm    
Pleasure. Happy Coding!!
Jay Katariya 6-Apr-22 16:09pm    
Sir i got many errors in this program of C# (methods) how can i fix this?

Question: Add another method called ShowMenu() to your project. This method will call the
method in question 7 continuously until the user presses 0. (You will have to invoke
the method in a loop body, read in the user input as well as check the input). You
will need to hook up all the methods that you wrote previously i.e. questions 1 to 6.
Replace all the code from your Main() method with a single call to the
ShowMenu() method.



using System;

namespace Q8
{
internal class Program
{
static void Main(string[] args)
{
static void ShowMenu()
{
int choice;
do
{
DisplayMenu();
choice = Convert.ToInt32(Console.ReadLine());

switch (choice)
{
case 1:
DisplayPersonalInfo();
break;
case 2:
CalculateTuition();
break;
case 3:
CalculateAreaOfCircle();
break;
case 4:
CalculateAreaOfTriangle();
break;
case 5:
for (int i = 1; i <= 3; i++)
{
CalculateSaleCommission();
}
break;
case 6:
DisplaySineTable();
break;
}
}
while (choice != 0);
}
}
}

}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900