#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int arraySize = 6;
double dailySales[arraySize];
for (int a=0 ; a <= arraySize; a++ )
{
cout << "Please enter sale number " << a+1 << " :";
cin >> dailySales[a];
}
cout << "\n\nSale Number" << setw( 13 ) << "Value" << endl;
for ( int i =0; i <= arraySize; i++ )
cout << setw( 5 ) << i << setw( 14 ) << dailySales[ i ] << endl;
for(int b = 0; b<=arraySize; b++)
for(int c = arraySize-1; c>=b; c--) {
if(dailySales[c-1] > dailySales[c]) {
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;
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();
cin.sync();
cout << "\n\nPress Enter to end the program\n\n";
cin.get();
return 0;
}
Conclusion:
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 the last value matters 7, but this is the number in sci. designation ??
source
share