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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:18:25+00:00 2026-05-27T07:18:25+00:00

When i go to print my array it prints, but there is extra data

  • 0

When i go to print my array it prints, but there is extra data at the end. The Extra Data is one line after the last line of output that should be there. it contains:” -13096448″ (note, it starts with a space.)

/***************************************************/
/* Author:     Sam LaManna                         */
/* Course:                                         */
/* Assignment: Program 6 Elves                     */
/* Due Date:   12/9/11                            */
/* Filename:   program6.cpp                        */
/* Purpose:    Write a program that will process   */
/*             the work done by santas elfs        */
/***************************************************/

#include <iostream>     //Basic input/output
#include <iomanip>      //Manipulators
#include <string>       //String stuff 
#include <fstream>      //File input/output

using namespace std;

void instruct ();     //Function Declaration for printing instructions 
void input (ifstream &infile, string &names, int &numoftoys);    //Function declaration for getting data from file
void headers ();     //Prints headers

int main()
{

  string names [50];       //Array for storing names
  int numoftoys [50];      //Array for storing the number of toys made
  int i = 0;
  int p = 0;

  ifstream infile("elves.dat"); //Opens input file "elves.dat"

  instruct();     //Function call to print instructions

  while (!infile.eof())
    {
      input (infile, names[i] , numoftoys[i]);
      ++i;
    }

  for (int p = 0; p<i; p++)
    {
      cout << names[p] << " " << numoftoys[p] << "\n";
    }



  return 0;
}




/***************************************************/
/* Name: instruct                                  */
/* Description: Prints instructions to user        */
/* Parameters: N/A                                 */
/* Return Value: N/A                               */
/***************************************************/

void instruct ()                                   
{
  cout << "\n" << "This program will calculate the toys made by santas elfs and assign" << "\n";
  cout << "a rating to each elf. It will also sort them and print average, min and max." << "\n";
  cout << "\n" << "Make sure you have a file named elves.dat in the same directory as";
  cout << " this porgram or you will recieve errors.";
  cout << "\n" << "\n";

  return;
}


/***************************************************/
/* Name: input                                     */
/* Description: Reads from file                    */
/* Parameters: N/A                                 */
/* Return Value: N/A                               */
/***************************************************/

void input (ifstream &infile, string &names, int &numoftoys)
{
  infile >> names;
  infile >> numoftoys;
  //  infile.ignore ('\n');

  return;
}

Data File:

Smiley 662
Curley 88
Clementine 335
Jasper 105
Lucinda 775
Brunhilda 103
Florence 441
Oskar 820
Snowflake 990
Bernard 690
Punch 298
Chuckie 10
Frosty 102
Snowman 311
April 830
Merry 299
Sunshine 331
Buddy 1234
Carol 271
Misty 111
Harold 52
Henry 292
Twinkle 308
Starlight 703
Burr 112
Angelica 444
Bluenose 689
Harry 254
Twinkle 259
Stardust 121
Greensleeves 453
Noel 312
Happy 209
Yukon 534
Snowcap 190
Northpole 598
  • 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-27T07:18:26+00:00Added an answer on May 27, 2026 at 7:18 am

    There are multiple problems with the input loop. It should probably read something like the following:

    while ((infile >> names[i]) && (infile >> numoftoys[i]))
    {
          ++i;
    }
    

    This avoids processing an extra line when the input fails and when there is a blank line at the end of the file (in which case the final .eof() test would succeed and input(...) would fail while still incrementing i.

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

Sidebar

Related Questions

I tryed to email me debug_backtrace() but it just prints out the array. I
I have an array of double pointers, but every time I try do print
I'm developing an ASP.NET handler with C# that receives an array of data posted
I am supposed to print an array of invoices to our clients. There is
int[] arrc = new int[] {1, 2, 3}; System.out.println(new ArrayList(Arrays.asList(arrc))); prints address, but i
When I learning to print array variables, I found the white space inserted when
I was trying to create a pseudo super struct to print array of structs.
I would like to print an array to a file. I would like the
How do you print out the contents of a 2d int array Ive code
What is the best way to print the cells of a String[][] array as

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.