Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1070875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:37:50+00:00 2026-05-16T20:37:50+00:00

Can someone tell me why this doesnt work. When I enter the loop it

  • 0

Can someone tell me why this doesnt work. When I enter the loop it prints everything instead of one line and get the users input. It prints Enter the integer the account numberEnter the integer the account balanceEnter the account holder lastname

Got it working thanks everyone, but now the searchaccounts doesnt work

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace ConsoleApplication1

{

class accounts

{

private int[] accountnum = new int[5]; //private accountnum array of five integer account numbers        

private int[] accountbal = new int[5];//private balance array of five balance amounts

private string[] accountname = new string[5];//private accntname array to hold five last names


        public void fillAccounts()
        {
            int bal;
            int accountnumber;
            string name;

            for (int x = 0; x < 5; ++x)
            {

                Console.Write("Enter the integer the account number");
                accountnumber = Console.Read();
                Console.Write("Enter the integer the account balance");
                bal = Console.Read();
                Console.Write("Enter the account holder lastname");
                name = Console.ReadLine();

                accountnum[x] = accountnumber;
                accountbal[x] = bal;
                accountname[x] = name;
            }




        }
        public void searchAccounts()
        {
            Console.WriteLine("Enter the account number");
            int acctnum = Console.Read();
            for (int x = 0; x < 6; ++x)
            {
                if (x < 5)
                {
                    if (accountnum[x] == acctnum)
                    {
                        Console.WriteLine("Account #{0} has a balance of {1} for customer {2}", acctnum, accountbal[x].ToString("C"), accountname[x]);
                        break;
                    }
                }
                else
                {
                    Console.WriteLine("You entered invalid account number");
                }
            }

        }
        public void averageAccounts()
        {
            int sum = 0;
            int avg;


            for (int x = 0; x < 5; ++x)
            {
                sum = accountbal[x] + sum;
            }
            avg = sum / 5;
            Console.WriteLine("The average dollar amount is {0}", avg.ToString("c"));
        }
    }
    class assignment3_alt
    {
        static void Main(string[] args)
        {
            accounts myclass = new accounts();
            string userin;


            myclass.fillAccounts();
            int i = 0;
            while (i != 1)
            {//use the following menu:            
                Console.WriteLine("*****************************************");
                Console.WriteLine("enter an a or A to search account numbers");
                Console.WriteLine("enter a b or B to average the accounts");
                Console.WriteLine("enter an x or X to exit program");
                Console.WriteLine("*****************************************");
                Console.Write("Enter option-->");
                userin = Console.ReadLine();
                if (userin == "a" || userin == "A")
                {
                    myclass.searchAccounts();
                }
                else if (userin == "b" || userin == "B")
                {
                    myclass.averageAccounts();
                }
                else if (userin == "x" || userin == "X")
                {
                    break;
                }
                else
                {
                    Console.WriteLine("You entered an invalid option");
                }
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T20:37:50+00:00Added an answer on May 16, 2026 at 8:37 pm

    Console.Read only reads a single character. You need to use Console.ReadLine.

    Console.Write("Enter the integer the account number");
    accountnumber = int.Parse(Console.ReadLine());
    Console.Write("Enter the integer the account balance");
    bal = int.Parse(Console.ReadLine());
    Console.Write("Enter the account holder lastname");
    name = Console.ReadLine();
    

    You might also want to consider using int.TryParse instead of int.Parse so that you can better handle invalid input.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone please tell me why this doesn't work? I'm trying to show and
Please can someone tell me why this isn't working before I defenestrate everything on
Can someone tell what is wrong with this query? sqltext = SELECT utyp, count(*)
Can someone tell me what the code equivelant in VB.Net to this C# code
Can someone tell me how to change directories using FtpWebRequest? This seems like it
Can someone tell me why: var nl = Convert.ToInt64(17029268.1650117); fails, and instead you have
this must be such a simple problem but can someone tell me why this
Hopefully someone can tell me whats going on with this little debugging script. <?PHP
Can someone please tell me where I'm going wrong with this piece of code?
So this should be pretty easy, yet I can't get it work. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.