x.Hmyone check my code? my bubble sort sometimes is working but sometimes don\'t
ID: 3615508 • Letter: X
Question
x.Hmyone check my code? my bubble sort sometimes is working but sometimes don't.sometimes it won't swap in the order. it suppose be the smallest commission to largest commission.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
#define RC 0.1 /*residential commission rate*/
#define CC 0.2 /*commercial commission rate*/
#define MC 0.15 /*multiunit dwelling commission rate*/
#define SIZE 50 /*size of arrays*/
double Thesmallest ( double comm[SIZE] , int numco);
double Thelargest ( double comm[SIZE] , int numco);
void Bsort(double table[SIZE],int size,int index[SIZE]);
int main ()
{
int Index[SIZE],
ID[SIZE],
yesno, /* loop controller, loops when = 1 or 0 */
numco = 0,
numcor = 0, /*number of residential*/
numico = 0, /*number of commercial*/
numcoi = 0, /*number of multiunit*/
numcoa = 0; /*total number of all commission*/
char prope, /*type of property*/
Ptype[SIZE];
double Sprice[SIZE],
largest, /*largest of commission*/
smallest, /*smallest of commission*/
comm[SIZE], /*commission*/
sell=0,
totr=0, /*total amount of residential commission*/
totc=0, /*total amount of commercial commission*/
totm=0, /*total amount of multiunit commission*/
total=0; /*total amount of all commission*/
string id;
cout << "Fernando Commission Computer";
do
{
cout <<endl;
cout << " Please enter 5 digit agent ID: ";
cin >> id ;
while (id.size()!= 5)
{
cout << "Invalid ID please enter 5 digit number " <<endl;
cin >>id;
}
ID[numco] = atoi(id.c_str());
cout << "Select the category of property sold ";
cout << endl;
cout << "R or r = residential, C or c=commercial, M or m=multiunit ";
cout << endl;
cout << "Your choice ";
cin >> prope;
while ( toupper(prope)!='R'&&toupper(prope)!='C'&&toupper(prope)!='M')
{cout << "Invalid property ";
cout << "Please re-enter property ";
cin >> prope;
}
switch (toupper(prope))
{
case 'R':
cout << "Please enter selling price " ;
cin >> sell;
while ( sell < 0)
{cout << "Invalid price ";
cout << "Please re-enter selling price ";
cin >> sell;
}
Sprice[numco] = sell;
comm [numco] = sell*RC;
Ptype[numco] = 'R';
totr += comm[numco];
cout << "Total amount of Residential commissions for Agent "<< fixed << setprecision(2) << id << " is: " << comm[numco] << endl;
numcor++;
numco++;
break;
Explanation / Answer
x.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.