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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:28:50+00:00 2026-06-13T10:28:50+00:00

Each time my program loops the data which is stored inside an int array[]

  • 0

Each time my program loops the data which is stored inside an int array[] is being cleared.

I did a count and count2 check every time it goes when the user selects the 1st option, but it is getting reset instead of the increment too.

#include <iostream>
#include <sstream>
#include <string>

using namespace std;

class MissionPlan //start of MissionPlan class
{
    public:
    MissionPlan();

}; //end of MissionPlan class


MissionPlan::MissionPlan()
{
    int choice; // to capture what user inputs into menu
    int count=0; // to count how many times it save into array and use it later for looping
    int count2=0;//for adding x and y coordinates correctly into array
    int coor [100]; //storing x and y coordinates
    float index[100];//storing the civ index
    cout<<"Welcome to Mission Plan program!"<<endl<<endl<<"1)      Input statistical data"<<endl<<"2)      Compute civ.index value(for all records)"<<endl<<
    "3)      Print top 5 exploration destinations"<<endl<<"4)      Print total travel distance"<<endl<<endl<<"Please enter your choice: ";
    cin>>choice;
    for(;;)
    {
        if(choice == 1)
        {   
            cout<<count<<endl;
            cout<<count2<<endl; 
            int x,y; // for reading x and y coordinate
            cout<<"Please enter x-ordinate: "; //Display x-ordinate
            cin>>x;//reading input from user and put into x
            coor[count2] = x;//storing x coordinate into coor[] array
            cout<<"Please enter y-ordinate: ";//Display y-ordinate
            cin>>y;//reading input from user and put into x
            coor[1+count2] = y;//storing y coordinate into coor[] array
            cin.clear();//clearing cin
            cin.ignore(10000,'\n');//to ignore char to 10000 and a linefeed
            count++;
            count2 +=2;
            cout<<count<<endl;
            cout<<count2<<endl;
            return;         
        }
        else if(choice == 2)
        {       
            cout<<"choice 2 "<<endl;//to display
            return;
        }
        else if(choice==3)
        {

            cout<<"choice 3"<<endl;

            return;
        }

        else
            cout<<"Please enter number 1 to 4 only!"<<endl;
    }//end of while loop
}//end of MissionPlan()
int main()
{

    for(;;)
{
MissionPlan();
}
    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-06-13T10:28:51+00:00Added an answer on June 13, 2026 at 10:28 am

    You declared your arrays inside the function MissionPlan(), so that they are under the stack. When the function returns (exited), there is no guarantee that the arrays will be kept, and they will most probably be “re-initialized”, that’s zeroed.

    If you need to preserve the content of the arrays, there are a few options, one of them is to declare the array in the global scope (i.e. outside all functions), another is to add the static modifier to the array variable so that the array is initialized only once and its content will be kept throughout the program:

    static int coor [100]; //storing x and y coordinates
    static float index[100];//storing the civ index
    

    One more option is to declare the variable inside main() function and pass them by function parameters.


    I saw you used class in your code but seems that you’re not using them appropriately: you just kept calling the constructor? (which I am quite confused whether it will work…)

    I think in your case you would simply define a simple function. Or if you really use class, keep an instance of it in main(), put the arrays and other variables that will be reused into the class, and make MissionPlan() a function instead of a constructor.

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

Sidebar

Related Questions

I want my program to get notification each time someone makes a post to
I'm getting an output data file of a program which looks like this, with
I have a simple program which loops through a resultset when a button is
Each time I use Merge() I have the following: 'Cannot implicitly convert type 'void'
Each time I add in the correct code, it gives me the same error
Each time my webpage is loaded it runs a routine in the page_load event
Each time I click on the map a new marker is placed on the
Each time I click the Run as button, I get the following message. The
Each time my user signs in, we pull his profile picture from Facebook. This
Each time I make changes to XML file and press run button, It generates

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.