Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 25th, 2007, 12:00 AM
Registered User
 
Join Date: Feb 2007
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Student Programming question

Hi there, I'm doing this assignment for school, and I have this allmost figured out, but I am getting 2 error messages: Here's the code, and what is is supposed to do is commented at the beginning:

Code:
//The program contains an array that holds
//10 ZIP codes to which a company delivers. 
//Prompt the user of the program to input a 
//ZIP code and then display a message on screen
//that indicates whether the ZIP code is one to 
//which the company delivers or not. Finally display
//all ZIP codes in the array in descending order.

using System;
public class ZipArray
{
    public static void Main()
    {
        int[] validZip = { 00001, 00002, 00003, 00004, 00005, 00006, 00007, 00008, 00009, 00010 };
        int x;
        string zipString;
        int entryId;
        Console.Write("Enter a Zip Code");
        zipString = Console.ReadLine();
        x = Array.BinarySearch(validZip, entryId);
        if (x = validZip)
            Console.WriteLine("Yes, we ship to zip code {0}", entryId);
        else
                    Console.WriteLine("We do not ship to Zip code {0}", entryId);

    }
}
public class SortArray
{
    public static void Sort()
    {
        int[] validZip = { 00001, 00002, 00003, 00004, 00005, 00006, 00007, 00008, 00009, 00010 };
        int x;
    Array.Sort(validZip);
    for(x=0; x<validZip.Length; ++x)
    Console.WriteLine(validZip[x]);
}
}
the error I am getting in having the program indicate whether or not the zip code is valid is on line 21

it says "cannot implicitly convert type 'int[]' to 'int'
and on the same line it says "cannot implicitly convert type 'int' to 'bool'

did I miss a for statement somewhere?

the second error is when I go to sort the zip codes in ascending order, it says
"The name 'Array' does not exist in the current context"
and
"the name 'Console' does not exist in the current context."

what does that mean?

 
Old February 26th, 2007, 07:24 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

"x = Array.BinarySearch(validZip, entryId);
        if (x = validZip)"

First.. Check if the args supplied are correct..
Second.. inside if you cannot use assignment operator....
and third... x is int and validZip is reference... use index...






Similar Threads
Thread Thread Starter Forum Replies Last Post
I have a question re: Oject Oriented Programming dotnetDeveloper General .NET 2 July 24th, 2008 05:33 PM
C programming question fadiyounes1 Other Programming Languages 1 February 6th, 2007 10:46 AM
Beginner SQL Programming Question monocles303 SQL Language 1 September 12th, 2006 03:47 AM
*student* in need of help satinder Access 2 April 4th, 2005 06:32 AM
Java Server Programming book question xyoon All Other Wrox Books 0 September 8th, 2003 01:45 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.