heather26 Posted January 5, 2006 Posted January 5, 2006 (edited) I am trying to write a programming code in Visual Studio and it is not working right when I enter the donor ID I get a message that says it is not found can anyone tell me what i am doing wrong here is the code: using System; namespace ETS { struct myDonor { public string donorID ; public string donorName; public double donorAmt; } /// <summary> /// Summary description for Class1. /// </summary> class Class1 { static string donorID; static myDonor[] donor= new myDonor[3]; static void myDonor() { // initialize customer #1 donor[0].donorID = "B505"; donor[0].donorName = "Campbell"; donor[0].donorAmt = 50.00; // initialize customer #2 donor[1].donorID = "D302"; donor[1].donorName = "Stewart"; donor[1].donorAmt = 200.00; // initialize customer #3 donor[2].donorID = "M002"; donor[2].donorName = "Wright"; donor[2].donorAmt = 25.00; } static double getDonorAmt(string donorID) { double donorAmt = 0; for (int i = 0; i < donor.Length-1; i++) { if (donorID == donor[i].donorID) { donorAmt = donor[i].donorAmt; } } return donorAmt; } /// <summary> /// The main entry point for the application. /// </summary> [sTAThread] static void Main(string[] args) { //AddDonors(); Console.WriteLine ("Please enter the donor ID: "); donorID = Console.ReadLine(); if (getDonorAmt(donorID)==0) { Console.WriteLine ("Donor {0} does not exist.", donorID); } else { Console.WriteLine ("Donor {0} has donated {1}", donorID, getDonorAmt(donorID)); } } } } Edited January 5, 2006 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted January 5, 2006 Administrators Posted January 5, 2006 The myDonor method is the one that adds the entries to the array but you are never calling it, hence every array item contains the default values. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.