473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How can i give an error depending on the array input?

Hello,
How can i give an error depending on the array input? This is my code

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. class MainClass
  3.  
  4. {
  5.         public static void Main (string[] args)
  6.         {
  7.         int[] randomSizedArray;
  8.         string sizeOfArray;
  9.         int convertedSizeArray = -1;
  10.         Console.WriteLine ("Please Enter the Size of the Array Between 1-99");
  11.         sizeOfArray = Console.ReadLine();
  12.         convertedSizeArray = Int32.Parse(sizeOfArray);    
  13.         randomSizedArray= new int[convertedSizeArray];
  14.         Random rnd = new Random();
  15.         for (int i=0; i < convertedSizeArray; i++) {
  16.  
  17.         randomSizedArray[i] = rnd.Next(1,99);
  18.  
  19.  
  20.         }
  21.             for (int i=0; i < convertedSizeArray; i++) 
  22. {
  23.     Console.WriteLine(randomSizedArray[i] + "");
  24.  
  25. }
  26.         string swapindex1;
  27.         string swapindex2;
  28.         int index1;
  29.         int index2;
  30.         Console.WriteLine("Please Enter Index to swap");
  31.         swapindex1 = Console.ReadLine();
  32.          index1 =  Int32.Parse(swapindex1);
  33.         int temp = randomSizedArray[index1];
  34.         Console.WriteLine ("Please Enter a Second Value to swap");    
  35.         swapindex2 = Console.ReadLine();
  36.          index2 =  Int32.Parse(swapindex2);    
  37.         randomSizedArray[index1] = randomSizedArray[index2];
  38.         randomSizedArray[index2] = temp;
  39.          for (int j=0; j < convertedSizeArray; j++){
  40.             Console.WriteLine(randomSizedArray[j]);
  41.     }
  42.  
  43.     }    
  44.  
  45.  
  46. }
  47.  
So im going to give an error if the user inputs different number besides 1-99, please help you guys, i've never done any error coding.
Apr 29 '13 #1
2 1304
Rabbit
12,516 Expert Mod 8TB
Use an if to check whether or not the inputted value is within your range. Throw an error if it is outside the range.
Apr 29 '13 #2
bharathreddy
111 100+
Rabbit is right, keep a if check before forloop on sizeOfArray variable. If it falls outside the allowed range then throw error message to the user.


Bharath Vasireddy
Apr 29 '13 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: TERMAN, IRA, ALABS | last post by:
Hello, I am trying to install Python-2.3. I get the following error when I run ./configure --with-csx=gcc on my Solaris machine. config.status: error: cannot find input file:...
1
by: Frank Jones | last post by:
When manually running resgen.exe from the command prompt (Visual Studio .NET 2003 command prompt) I get the following error: error: Invalid ResX input. error: Specific exception:...
7
by: Fendi Baba | last post by:
The function is called from opencalendar(targetfield). Thanks for any hints on what could be the problem. .............................................................. var...
1
by: Srilatha | last post by:
Hi, I want to read a file as a Byte Array Input Stream in VB.Net. How can I declare a Byte Array Input Stream?
4
by: David W. Fenton | last post by:
I'm working on a subform where users put in 24-hour time. On their paper forms, they've been accustomed to referring to midnight as 24:00 (instead of as 0:00, which kind of makes sense from a human...
3
by: wwwursa | last post by:
I am trying to use the Right function in a VB6 program. I have used it used many times before in other programs. When I press the enter key after entering the code line, the word "Right" turns...
1
by: Sister Ray | last post by:
Hello, I'm trying to debug and compile a application that was developed by a collegue of mine, How ever when i try to build the application I always receive the following error: Compiling...
2
by: shardul21 | last post by:
hi i am new to java programming.can anyone tell me about how to take array input from user in java program?. also why java is difficult regarding inputs from keyboard(user)?
1
by: kieran04 | last post by:
every time i run this program in VBE i keep getting the message 'Compile Error: expected array' for the two bold lines underneath, please help? Public Function KnotsToKmPerHr(knots As...
4
by: Lindsay Bradley | last post by:
I have code built into a form in Access and everytime I try to open the form it gives me a Compile error: Expected array message and then highlights the word Left. I did not create this program and...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.