C++ class debug

When I try to debug the console terminal pops up and disappears right away.
I'm using visual studio c++ 2008.
The output I'm getting is :
'greedy1.exe': Loaded 'C:\Users\Emi\Documents\Visual Studio 2008\Projects\greedy1\Debug\greedy1.exe', Symbols loaded.
'greedy1.exe': Loaded 'C:\Windows\SysWOW64\ntdll.dll'
'greedy1.exe': Loaded 'C:\Windows\SysWOW64\kernel32.dll'
'greedy1.exe': Loaded 'C:\Windows\SysWOW64\KernelBase.dll'
'greedy1.exe': Loaded 'C:\Windows\WinSxS\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcp90d.dll', Symbols loaded.
'greedy1.exe': Loaded 'C:\Windows\WinSxS\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.21022.8_none_96748342450f6aa2\msvcr90d.dll', Symbols loaded.
The program '[4904] greedy1.exe: Native' has exited with code 0 (0x0).

I tried running different code,and it worked,so the problem is related with this particular code.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <conio.h>
#include <iostream>
#pragma warning (disable : 4996)
using namespace 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 ==========
Last edited on
You need a closing brace for your class.
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 ==========

I've updated the code in my first post
Last edited on
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.
Thanks for the help,it works fine now.And il keep that in mind next time I post
Last edited on
Topic archived. No new replies allowed.