can you fix my code in c++? #include #include #define SIZE 3 using namespace std; string readType() { string *type = new string; cout << "Drone type: "; getline(cin, *type); return type; } void readData(string dtype, int *d_info[]) { cout << dtype; cin >> d_info; } int highestType(string *dt[], int *d_price, int *d_qty) { float sales; int d_Highest; int index; d_Highest=*d_price(); cout<<"Sales Amount : "<
can you fix my code in c++?
#include <iostream>
#include <string>
#define SIZE 3
using namespace std;
string readType() {
string *type = new string;
cout << "Drone type: ";
getline(cin, *type);
return type;
}
void readData(string dtype, int *d_info[]) {
cout << dtype;
cin >> d_info;
}
int highestType(string *dt[], int *d_price, int *d_qty) {
float sales; int d_Highest;
int index;
d_Highest=*d_price();
cout<<"Sales Amount : "<<endl;
for (int i = 0; i < SIZE; i++) {
sales=(float)*d_price[i] * (*d_qty[i]);
cout << *dt[i] << " - " <<"RM"<< sales << "\n";
if (sales<d_Highest) {
d_Highest = sales;
index = i;
}
}
cout << "\n";
return index;
}
//Start main function
int main() {
string *dtypes [SIZE];
int *dprice;
int *dqty [SIZE];
// Examples of type, sales price and sales quantity of drone
// DJI Mini2 - RM 2000 - 200 qty
// DJI Phantom4 - RM 5500 - 400 qty
// DJI PhantomPro - RM 6150 - 30 qty
for (int x = 0; x < SIZE; x++) {
dtypes[x] = readType();
dprice[x] = new Int;
readData("Sales price (RM): " , dprice[x]);
dqty[x] = new Int;
readData("Sales quantity : " , dqty[x]);
cin.ignore(); // need this as we mix the use of getline and cin
cout << "\n";
}
int idx1 = highestType(dtypes, dprice, dqty);
cout << "Highest amount sales is for drone type " << *dtypes[idx1]
<< " priced at RM " << *dprice[idx1] << " for "
<< dqty[idx1] << " of sales amount\n\n";
// delete array data from memory
for (int x = 0; x < SIZE; x++) {
delete dtypes[x];
delete dprice[x];
delete dqty[x];
}
return 0;
}
output
Drone type: DJI Mini2
Sales price (RM): 2000
Sales quantity : 200
Drone type: DJI Phantom4
Sales price (RM): 5500
Sales quantity : 400
Drone type: DJI PhantomPro
Sales price (RM): 6150
Sales quantity : 30
Sales Amount :
DJI Mini2 - RM400000
DJI Phantom4 - RM2.2e+06
DJI PhantomPro - RM184500
Highest amount sales is for drone type DJI Phantom4 priced at RM
5500 for 400 of sales amount
Step by step
Solved in 2 steps with 1 images