#include <conio.h>
#include <iostream>
#pragma warning (disable : 4996)
usingnamespace std;
class Greedy
{ int o[100],N,M;
float val[100],weight[100],x[100],Gr;
public:
void imput()
{
int i;
cout<<"Imput maximum weight and number of objects"<<endl;
cin>>M>>N;
for (i=0;i<N;++i)
{
o[i]=i;
cout<<"Imput value and weight of objects"<<i+1<<endl;
cin>>val[i]>>weight[i];
}
}
void order()
{
int i,aux,check;
do
{check=0;
for(i=0;i<N-1;++i)
if(val[o[i]]/weight[o[i]]<val[o[i+1]]/weight[o[i+1]])
{aux=o[i];
o[i]=o[i+1];
o[i+1]=aux;
check=1;
}
}
while(check);
}
void solve()
{
int i;
for(i=o,Gr=M;i<N && Gr>weight[o[i]];i++)
{x[o[i]]=1;
Gr-=weight[o[i]];
}
}
void output()
{ int i;
for(i=0;i<N;i++)
if(x[i])
cout<<i+1<<" "<<x[i]*100<<endl;
}
};
void main()
{
Greedy g;
g.imput();
g.order();
g.solve();
g.output();
_getch();
}
Edit:Worked around my first problem and now I'm getting this,but i don't undestand what variable the error message is referring at,or how I should fix it
1>greedy 3.cpp
>Compiling...
1>greedy 3.cpp
1>e:\cursuri\poo\aplicatii\greedy3\greedy3\greedy 3.cpp(39) : error C2440: '=' : cannot convert from 'int [100]' to 'int'
1> There is no context in which this conversion is possible
1>e:\cursuri\poo\aplicatii\greedy3\greedy3\greedy 3.cpp(39) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Build log was saved at "file://e:\cursuri\poo\aplicatii\greedy3\greedy3\Debug\BuildLog.htm"
1>greedy3 - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
There are several things that are wrong in the code that you have pasted:
1. As mentioned, finish the class definition with a brace
2. On line 13 and 18 replace << with >>
3. What is the meaning of semicolon at the end of line 27? It means that the if does not have any effect
4. On line 27, what does o[i+] mean? Did you want to have o[i+1]? If that is the case, there it is the reason why your program crashes. At the last i (N-1) i+1 = N, but your array goes only to N-1. You should replace on line 26 N with N-1.
Mult succes. Data viitoare cand postezi, schimba numele fucntiilor, comentarilor in engleza. E mai usor pentru altii sa-ti citeasca programul
I've made the corrections you have listed above,but im getting a diferent set of errors now.Managed to narrow it down to these ones,but i cant figure out how to debug this ones:
1>greedy 3.cpp
>Compiling...
1>greedy 3.cpp
1>e:\cursuri\poo\aplicatii\greedy3\greedy3\greedy 3.cpp(39) : error C2440: '=' : cannot convert from 'int [100]' to 'int'
1> There is no context in which this conversion is possible
1>e:\cursuri\poo\aplicatii\greedy3\greedy3\greedy 3.cpp(39) : warning C4244: '=' : conversion from 'int' to 'float', possible loss of data
1>Build log was saved at "file://e:\cursuri\poo\aplicatii\greedy3\greedy3\Debug\BuildLog.htm"
1>greedy3 - 1 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
On line 39, i is an integer, o is an array. Did you mean i=0? Also, next time leave the original code intact. People will not understand your question if you change the code. Better paste it again.