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 7491753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:07:31+00:00 2026-05-29T16:07:31+00:00

Alright, I’m extremely new to programming so odds are this is a really easy

  • 0

Alright, I’m extremely new to programming so odds are this is a really easy fix but for some reason, I’m receiving an Input string was not in a correct format error. When I try to parse a string value from a file to double when I’m pretty sure the string being input is definitely a number that can be parsed to double. What’s strange is that I checked the array and all the info gets placed into the array perfectly. So I really don’t understand why I’m getting this error.

Here’s the code for the method that I’m getting the error from:

I receive the error Input string was not in a correct format in the method LoadArray() at the line that says annualInterestRate = Double.Parse(fields[0]);.

This is the info I have in the input file in the same formatting:

.015 20000 w8v6754r6 Jacobs,Michael
.045 60000 w4fg55566 Ray,Bill
.035 40000 w6gyhygg7 Nichols,Luke
.018 25000 w5g55g777 Hendricks,Gary

The rest of the code from that class is just there in case, but really the problem is most likely in the LoadArray() method. Thanks in advance!

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

namespace SavingsAccount
{
    class Driver
    {
        public static void LoadArray(SavingsAccount [ ] array)
        {
            string accountHolder = " ";
            string accountNumber = " ";
            double annualInterestRate = 0.0;
            double savingsBalance = 0.0;
            int i = 0;


            StreamReader inFile = new StreamReader("accountdata.txt");

            SavingsAccount account1 = new SavingsAccount();

            //set to default constructor
            for (int j = 0; j < array.Length; j++)
                array[j] = new SavingsAccount();

            while (!inFile.EndOfStream)
            {


                //input file
                string[] fields = inFile.ReadLine().Trim().Split(' ');
                annualInterestRate = Double.Parse(fields[0]);
                savingsBalance = Double.Parse(fields[1]);
                accountNumber = fields[2];
                accountHolder = fields[3];


                //annualInterestRate = Double.Parse(inFile.ReadLine());
                //savingsBalance = Double.Parse(inFile.ReadLine());
                //accountNumber = inFile.ReadLine();
                //accountHolder = inFile.ReadLine();


                //set info from input file
                account1.setAccountNumber(accountNumber);
                account1.setAccountHolder(accountHolder);
                account1.ModifyInterestRate(annualInterestRate);
                account1.ModifySavingsBalance(savingsBalance);

                array[i] = new SavingsAccount(annualInterestRate, savingsBalance, accountNumber, accountHolder);
                i++;




            }//end while
            inFile.Close();
        }//end method

        public static void SavingsReport( SavingsAccount [ ] array)
        {
            SavingsAccount account1 = new SavingsAccount();
            Console.WriteLine("------------------------Savings Report-----------------------------");
            Console.WriteLine("Interest Rate   Savings Balance    Account Number    Account Holder");
            Console.WriteLine("-------------------------------------------------------------------");
            for (int i = 0; i < array.Length; i++)
            {

                Console.WriteLine(account1.ToString());
            }

            Console.WriteLine("-------------------------------------------------------------------");
            Console.WriteLine();
            //use array as parameter
        }

        public static void StoreAccounts( SavingsAccount [ ] array)
        {
            SavingsAccount account1 = new SavingsAccount();
            StreamWriter outFile = new StreamWriter(@"C:\Users\Juan D Sanchez\Desktop\accountholderdata.txt");
            //use array as parameter
            outFile.WriteLine("------------------------Savings Report-----------------------------");
            outFile.WriteLine("Interest Rate   Savings Balance    Account Number    Account Holder");
            outFile.WriteLine("-------------------------------------------------------------------");
            for (int i = 0; i < array.Length; i++)
            {
                outFile.WriteLine(account1.ToString());
            }

            outFile.WriteLine("-------------------------------------------------------------------");
            outFile.WriteLine();

        }

        static void Main(string[] args)
        {


            SavingsAccount[] Accounts = new SavingsAccount[100];

            LoadArray(Accounts);

            SavingsReport(Accounts);

            StoreAccounts(Accounts);



            //for (int i = 0; i < Accounts.Length; i++)
            //{

            //}
            //exits the program after the user enters any key
            Console.WriteLine("Press any key to close.....");
            Console.ReadKey();

        }//end main

    }//end class
}
  • 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-29T16:07:34+00:00Added an answer on May 29, 2026 at 4:07 pm

    Check your file and make sure there’s no empty line at the end. Also make sure that fields are veing populated correctly.

    I would add breakpoint at the line you are getting the error and go through line by line to find out what data is being passed.

    Hope it helps.

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

Sidebar

Related Questions

Alright, so I'm new to Android programming, so far my experience has been quite
Alright. I have a query that looks like this: SELECT SUM(`order_items`.`quantity`) as `count`, `menu_items`.`name`
Alright, so I have a query that looks like this: SELECT `orders`.*, GROUP_CONCAT( CONCAT(
Alright, i have read many different views on how to do this with no
Alright so this is a bizarre cross platform thing that I'm experiencing with text
Alright, I'm injecting some code into another process using the CreateRemoteThread/LoadLibrary trick. I end
Alright, I've just finished normalizing a table. What I didn't really consider when I
Alright I am having a world of difficulty tracking down this memory leak. When
Alright so i have been working on this Dynamic load of a spinner from
Alright, so I'm writing this program that essentially batch runs other java programs for

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.