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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T23:30:47+00:00 2026-05-31T23:30:47+00:00

Ok, this was an assignment that I was deducted points due to the fact

  • 0

Ok, this was an assignment that I was deducted points due to the fact that the output was displayed backwards. I was supposed to prompt the user for input then display the input in descending order, but I am having an issue with the display. I have two arrays, one year[] to hold the months and one month[totalMonths] to hold the user input. When i sort and display the input the year[] does not correspond with the months, it is fixed. So for example if the user enters 1 for Jan, 2 for Feb and 3 for Mar, the display would be;
Jan: 3
Feb: 2
Mar: 1

Any ideas on how i can get the months to correspond with the its proper input for the display? Here is the sort and display function:

void sortArray(double month[], string year[], int totalMonths)
{
    int temp;
    bool swap;
    do
    {
        swap = false;
        for(int count = 0; count < totalMonths - 1; count++)
        {
            if(month[count] < month[count + 1])
            {
                temp = month[count];
                month[count] = month[count + 1];
                month[count + 1] = temp;
                swap = true;
            }
        }
    } while(swap);
    cout << "------------------------------------------------------------" << endl;
    cout << "Here are the months rainfall statistics sorted from highest to lowest: " << endl;

    for (int index = 0; index  < totalMonths; index++)
        cout << year[index] << "\t " << setw(5) << month[index] << endl;
}

Here is my string year[] definition:

string year[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
            "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};  
  • 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-31T23:30:48+00:00Added an answer on May 31, 2026 at 11:30 pm

    Are you allowed to rearrange the year array? In your sort routine, where you swap the month values, you can swap the corresponding values in the year array.

    If you don’t want to mutate the year array you can just add a level of indirection. Define an array of indices into the month and year arrays and sort the indices.

    int index[12] = { 0,1,2,3,4,5,6,7,8,9,10,11 };
    
    // inside your sort routine...
    
    if(month[index[count]] < month[index[count + 1]])
    {
        temp = index[count];
        index[count] = index[count + 1];
        index[count + 1] = temp;
        swap = true;
    }
    
    // print the arrays...
    
    for (int count = 0; count  < totalMonths; count++)
        cout << year[index[count]] << "\t " << setw(5) << month[index[count]] << endl;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

OK, I have this assignment and I have to prompt the user for data
I have this assignment due that requires the usage of FLTK. The code is
My class assignment is to write a program that has the user input a
I am doing this assignment, and there are some stuff (from start-up materials) that
I am working on an assignment that is giving me grief. I am supposed
I have this programming assignment that converts between meters and feet, and between kilograms
This is an assignment that I've been given, it says that if an hash-set
This is a class assignment that must be done using a dynamically created array
Part of this assignment includes printing out on the display the current equation that
I'm currently working on a program (for fun, this is not an assignment) that

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.