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

  • Home
  • SEARCH
  • 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 8344285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:19:03+00:00 2026-06-09T06:19:03+00:00

I have been given a simple task, that I cannot seem to figure out

  • 0

I have been given a simple task, that I cannot seem to figure out how to accomplish it.

I have been given a text file that has both names and pay rate/hours of employees. The format is as follows:

Mary Jones
12.50 30
Bill Smith
10.00 40
Sam Brown
9.50 40

My task is to write a program that uses StreamReader to pull the data from a text file, then print the employees name, and calculate the total pay by multiplying the rate and hours.

I know how to split the line with a .Split method, however I can’t seem to figure out how to seperate the names from the doubles/ints. My parse methods always come back with a format error because it reads the strings first. I am completely stuck.

Here is my code so far, any help or guidance would be appreciated.

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

namespace lab21
{
    class Program
    {
        static void Main(string[] args)
        {

            StreamReader myfile = new StreamReader("data.txt");
            string fromFile;

            do
            {
                fromFile = myfile.ReadLine();
                if (fromFile != null)
                {
                    string[] payInfo = fromFile.Split( );
                    double wage = double.Parse(payInfo[0]);
                    int hours = int.Parse(payInfo[1]);
                    Console.WriteLine(fromFile);
                    Console.WriteLine(wage * hours);
                }
            } while (fromFile != null);
        }
    }
}
  • 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-06-09T06:19:05+00:00Added an answer on June 9, 2026 at 6:19 am

    Use Decimal.Parse and read two line:

    do
    {
        name = myfile.ReadLine();
        if (name != null)
        {
            // read second line
            var nums = myfile.ReadLine();
            if (nums != null)
            {
                string[] payNums = nums.Split(new[] {' '});
                Console.WriteLine("{0}: {1}", 
                                  name,
                                  Decimal.Parse(payNums[0])
                                  * Decimal.Parse(payNums[1]));
            }
        }
    } while (name != null);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been given a task to create a Python file that will take
I Have been given this simple task , I have this list where i
I have been given a task that can be simplified to this scenario: Customers
i Have been given this simple task , I want to connect to facebook
I have been given two different Microsoft Word document that my virus scanner has
I have been given some poorly formatted data and need to pull numbers out
We have been given a site xyz.com, in which the home page has images
I have been given the task of adding functionality to an existing IIS 6.0
I have been given the unenviable task of cleaning up after a developer who
I have been given the painful task of writing a C# application to sync

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.