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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:07:57+00:00 2026-05-20T02:07:57+00:00

//Page 215, #2, by Jeremy Mill //program taken in 7 values, displays them, and

  • 0
//Page 215, #2, by Jeremy Mill
//program taken in 7 values, displays them, and then sorts them from highest to     lowest, and displays them in order.

#include <iostream>
#include <iomanip>

using namespace std;

int main()
{
//Define the variable we will need  
const int arraySize = 6;
double dailySales[arraySize];

//Now let's prompt the user for their input
for (int a=0 ; a <= arraySize; a++ )
    {
    cout << "Please enter sale number " << a+1 << " :";
    cin >> dailySales[a];
    }

//Now we display the output of the array
cout << "\n\nSale Number" << setw( 13 ) << "Value" << endl;
    for ( int i =0; i <= arraySize; i++ )        
        cout << setw( 5 ) << i << setw( 14 ) << dailySales[ i ] << endl;

//Now we sort using a bubble sort
for(int b = 0; b<=arraySize; b++)
        for(int c = arraySize-1; c>=b; c--) {
            if(dailySales[c-1] > dailySales[c]) { // if out of order
            // exchange elements 
            int t = 0;        
            t = dailySales[c-1];
                dailySales[c-1] = dailySales[c];
                dailySales[c] = t;
            cout << "it ran";
            }
        }   

cout << "Now we can display the array again! \n\n\n" << endl << dailySales[6] << endl;

//Now we display the output of the sorted array
cout << "\n\nSale Number" << setw( 13 ) << "Value" << endl;
    for ( int d = 0; d <= arraySize; d++ )        
        cout << setw( 5 ) << d << setw( 14 ) << dailySales[ d ] << endl;

cin.clear(); //clear cin
cin.sync(); //reinitialize it
cout << "\n\nPress Enter to end the program\n\n"; //display this text
cin.get(); //pause and wait for an enter
return 0;  

} // end main

Output:

Please enter sale number 1 :1
Please enter sale number 2 :2
Please enter sale number 3 :3
Please enter sale number 4 :4
Please enter sale number 5 :5
Please enter sale number 6 :6
Please enter sale number 7 :7


Sale Number        Value
    0             1
    1             2
    2             3
    3             4
    4             5
    5             6
    6             7
Now we can display the array again! 



7


Sale Number        Value
    0             1
    1             2
    2             3
    3             4
    4             5
    5             6
    6  2.97079e-313


Press Enter to end the program

Why is it that the last ‘value’ is not 7, but that number in sci. notation??

  • 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-20T02:07:58+00:00Added an answer on May 20, 2026 at 2:07 am

    Be carreful when looping through your array. The loop has to start from 0 to size-1.
    So instead of using less-than-or-equal:

    for (int a = 0; a <= arraySize; a++)
    

    You should use less-than:

    for (int a = 0; a < arraySize; a++)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

From page 90 of Erlang Programming by Cesarini and Thomson, there is an example
my Page has many hover images, sometimes there are backgrounds from div-elements or src
I make code to display multiple pages (max. 5 lines/page) with persons from one
Ok i have a telerik:RadRotator on my page that loads a few images from
Page 215 of the CF9 Web Application Construction Kit volume 1 says Most newer
I have lot of this hyperlink in my page. Some of them are visible
Possible Duplicate: T-SQL Pivot? Possibility of creating table columns from row values I've been
Page has a header and an iFrame. The iFrame has content from a 3rd
I need to discover the origin of a page view: click from Menu, Banner,
Page is refreshed every 5 seconds. Images that received from .php file are appended

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.