Fractional Knapsack 2 (struct)

#include <cstdlib>
#include <iostream>

using namespace std;
struct knapsack{
float p,w,pw,x; //profit,berat,nilai dari p/w,nilai probabilita barang yang masuk
char barang;
}


void swap(T *c,int i,int j){
T temp;
temp=c[j];
c[j]=c[i];
c[i]=temp;
return;}

void Pengurutan(knapsack c[], int n){
for(int i=0;i<=n;i++){
for(int j=0;i<=n;i++){
if(c[i].pw tukar(c[i],c[j];
}
}
}

void SolveFractorialKnapsack(knapsack c[], float w, int n,float  &TotalUntung){
int i;
float kapasitas;
bool MasihMuatUtuh;
for (i=0;i<=n;i++){
c[i].x=0;
}
kapaitas=W;
TotalUntung=0;
i=1;
MasihMuatUtuh=true;
while ((i<=n) && (MasihMuatUtuh)){
if(c[i].w<=kapasitas){
c[i].x=1;
totalUntung = totalUntung + c[i].p;
kapasitas = kapaitas - c[i].w;
i++
}
else{
MasihMuatUtuh=false;
}
}
if(i<=n){
c[i].x=kapaitas/c[i].w;
totalUntung = totalUntung+c[i].x*c[i].p;
}
}
int main(int argc, char *argv[])
{
float c[100];
int n,W; //kapaistas
char j=0;

cout<<"Jumlah barang: "; cin>>n;
for(int i=0;i cout<<"Barang: "< c[i].barang=j+1;
cout<<"Profit: "; cin>>c[i].p;
cout<<"Berat: " cin>>c[i].w;
c[i].pw=c[i].p/c[i].w; //hitung nilai pw
}
cout<<"Kapasitas :";cin>>W;
system(“PAUSE”);
return EXIT_SUCCESS;
}


Komentar