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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T01:26:35+00:00 2026-06-16T01:26:35+00:00

Alright so I have an assignment that I have been completely stumped on. My

  • 0

Alright so I have an assignment that I have been completely stumped on. My code thus far is as follows

#include<iostream>
#include<cstdlib>
#include<fstream>
#include<sstream>

using namespace std;

const int SIZE = 12;

struct Division
{
      char divName[SIZE]; // Division name
      double sales[4]; // Quarterly sales stored as an array
};



int main()
{
       void Intro();
       Division CreateCorporateFile();
       Division DisplayCorporateSales();

       Intro();
       CreateCorporateFile();
       DisplayCorporateSales();


       system("PAUSE");
       return 0;
}

void Intro()
{
     cout<<"This program will prompt you to enter in quarterly sales for "
           "four different\ndivisions of a company.\n\n";
}


Division CreateCorporateFile()
{
     Division div;
     int x = 0;
     //for(int x = 0; x < 4; x++)
 do {
          int quarter = 1;
          cout << "Enter the name of the division: ";
          cin >> div.divName;
          for(int i = 0; i < 4; i++)
          {
              cout << "Enter in the sales for quarter "<< quarter <<": ";
               cin >> div.sales[i];
               if(div.sales[i] > 0)
               {
                    quarter++;
               }
               else
               {
                    cout << "Sales are not allowed to be negative.\n";
               }
          }
          x++;
     } while(x < 4);

     return div;
}


Division DisplayCorporateSales()
{
         Division test;

         Division CreateCorporateFile();

         test = CreateCorporateFile();

         for(int i = 0; i < 4; i++)
         {
             cout << "Here are the quarterly sales for " << test.divName
              << ": ";
             for(int i = 0, quarter = 1; i < 4; ++i, ++quarter)
             {
                  cout << "Quarter "<< quarter << " sales: $"<< test.sales[i]
                   <<"\n";
             }
         }

         return test;

}

One of the problems that I am running in to is that it ends up prompting for 8 divisions (should only do it 4 times), and another is that it ends up only displaying the 8th divisions data. So anybody see where I am going wrong? Because I do not, and I have been working on it for hours so I am probably overlooking obvious details.

  • 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-16T01:26:36+00:00Added an answer on June 16, 2026 at 1:26 am

    The reason you only display data for the final Division is that CreateCorporateFile only returns a single Division instance. Each do-while loop overwrites the contents of the previous loop.

    One solution to this would be to return an array instead

    std::vector<Division> CreateCorporateFile()
    {
        std::vector<Division> divArray;
        Division div;
        int x = 0;
        do {
            ...
            divArray.push_back(div);
            x++;
        } while(x < 4);
    
        return divArray;
    }
    
    void DisplayCorporateSales()
    {
        std::vector<Division> divisions = CreateCorporateFile();
        for (size_t i=0; i<divisions.size(); i++)
        {
            Division div = divisions[i];
            cout << "Here are the quarterly sales for " << div.divName
            << ": ";
            for(int j = 0, quarter = 1; j < 4; ++j, ++quarter)
            {
                cout << "Quarter "<< quarter << " sales: $"<< div.sales[j]
                <<"\n";
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Alright I have a question that seems simple but I haven't been able to
Alright have been working to switch to jQuery 1.7's new and improved .on() function
Alright so I have been looking around (on SO and Google) to see if
Alright so I have been trying to get all of my separate classes (At
Alright as I have been asking the last couple days and inching closer and
Alright so I have a task, that I have to let the client try
Alright, so I have this collision detection code, and I'm trying to push the
Alright, I have this program to sparse code in Newick Format, which extracts both
Alright so i have been working on this Dynamic load of a spinner from
Hey, alright so I have a .plist that looks like; <plist version=1.0> <dict> <key>Item

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.