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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:55:20+00:00 2026-05-29T05:55:20+00:00

Hello everyone I am doing a programming assignment on structured data and I believe

  • 0

Hello everyone I am doing a programming assignment on structured data and I believe I understand how structs work.

I am trying to read in a list of student names, ID numbers (A-Numbers), and their balances.

When I compile my code though, it will read everything in the first time around, but the second time around the loop and every time after, it prompts for the username but skips the getline and goes straight to A-Number and A-number entry.

Any help would be appreciated. Just trying to figure out how to make the getline work every time the loop goes around.

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;


int main(){
    const int maxStudents = 30;
    struct Students{
        string studentName;
        int aNumber;
        double outstandingBalance;};

    Students students[maxStudents];

    for(int count = 0; count < maxStudents-1; count++)
    {
        cout<<"Student Name:";
                cin.ignore();
        getline(cin,students[count].studentName);
        cout<<"\nA-Number:";
        cin>>students[count].aNumber;
        if(students[count].aNumber == -999)
            break;
        cout<<"\nOutstanding Balance:";
        cin>>students[count].outstandingBalance;
    }

    cout<<setw(20)<<"A-Number"<<"Name"<<"Balance";

    for(int count2 = 29; count2 >= maxStudents-1; count2--)
        cout<<setw(20)<<students[count2].aNumber<<students[count2].studentName<<students[count2].outstandingBalance;


    system("pause");
    return 0;
}
  • 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-29T05:55:21+00:00Added an answer on May 29, 2026 at 5:55 am

    The reason what you’re doing doesn’t work is that the ‘>>’ operators the
    first time through don’t extract the trailing '\n', the next getline
    sees it, and returns immediately with an empty line.

    The simple answer is: don’t mix getline and >>. If the input is
    line oriented, use getline. If you need to parse data in the line
    using >>, use the string read by getline to initialize a
    std::istringstream, and use >> on it.

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

Sidebar

Related Questions

Hello everyone I'm trying to work with jboss messaging, does anyone knows the default
hello everyone I'm trying to write function which can unfold int in the list
Hello Everyone Iam trying to bulk insert data from .dat file(unloaded from sybase) in
Hello everyone I am trying to make since of what I am doing wrong
Hello everyone I am trying to resize an image of 700kb with imagecreatefromjpeg. This
Hello everyone I'm trying to improve my Java skills by solving some problems from
Hello everyone i am trying to format the input number range with php number_format
Hello everyone I want to ask a question about including guards in C programming.
Hello everyone I am just learning my first programming language and have just corrected
Hello everyone this is my first post on stack overflow.com I am trying to

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.