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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:39:29+00:00 2026-06-15T17:39:29+00:00

The program I code below should List all payment made by each student, show

  • 0

The program I code below should
List all payment made by each student, show amount paid and outstanding

I need some help with the following section:

void payment()
{
    // Display message asking for the user input
    std::cout << "List all payment made by each student, show amount paid and outstanding." << std::endl;

    // Read from text file and Display list of payment

    std::ifstream infile;               // enable to open, read in and close a text file
    float StudentCode;                  // to store the student enrolment number
    float Amount;                       // to store the amount of money
    float Type;                         // to store information on type of payment made
    float Outstanding;                  // to store amount of money is due

    infile.open("Payment.txt");         // open a text file called Payment

    if (!infile)                 
    {
        std::cout << "Item list is empty" << std::endl;     // if the file is empty it output the message
    } 
    else 
    {
        std::cout << "List of Payment: " << std::endl;
        std::cout << "" << std::endl;
        std::cout << "Enrolment No." << "Amount" << "Outstanding" << std::endl;

        // If there is Student Code that has the same number, it need to combined the amount it paid 
        // For an example 
        // Student Code: 12 Amount: 25
        // Student Code: 12 Amount: 50
        // so it should display the following when the program runs:
        // Student Code: 12 Amount: 75

        while(!infile.eof())            // output the description of the text file onto the screen
        {
            getline(infile,StudentCode,Amount);

            Outstanding = Amount - 100;

            std::cout << StudentCode << Amount << "$" << Outstanding << std::endl;
            //iter++;
        }
        std::cout << "End of list\n" << std::endl;
    }

    infile.close();         // close the text file  
}

What is wrong with the getline part:

getline(infile,StudentCode, Amount);

Also the program should not display repeated Student Code but combine the amount it paid.
Where I explain in the comment section

// If there is Student Code that has the same number .....

How do I do this?

  • 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-15T17:39:29+00:00Added an answer on June 15, 2026 at 5:39 pm

    getline reads a line from a stream into a string. What you’re trying to do, is more like this

    while (infile >> StudentCode >> Amount) {
        // process values
    }
    

    If you want to sum up all amounts, you must first accumulate and afterwards loop through the collected values and print them

    std::map<int, float> amountsPaid;
    int studentCode;
    float amount;
    // accumulate amounts
    while (infile >> studentCode >> amount) {
        amountsPaid[studentCode] += amount;
    }
    
    // loop through map and print all entries
    for (auto i = amountsPaid.begin(); i != amountsPaid.end(); ++i) {
        float outstanding = i->second - 100;
        std::cout << i->first << ": " << i->second << "$, " << outstanding << '\n';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The code below should do the following: List all students taking a module, showing
This code below doesn't work correctly since my MFC program is in unicode circumstance.
I have below code: class Program { static void Main(string[] args) { Task[] tasks
This is my code below. The program runs fine. I don't get any exceptions.
I have wrote the code below which was taken from Java How to program
I coded the code below. I've used it in my program and it seems
I'm working on a picture select/crop program and using this code below: http://www.androidworks.com/crop_large_photos_with_android/comment-page-1#comment-969 As
The code pasted below is a simple JSF program, with an idea of having
I have written a MapReduce program, code is below: import java.io.IOException; import java.util.Iterator; import
Given below is program for encrypting a string. I had taken this code from

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.