int main() versus void main()

Pages: 123
post your code..
but im telling u, it fixed my problem, some1 posted a link on THIS topic about that, and then i came to the idea that void main() was the problem, because in that article says that it can affect protabilety

here is my new 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
#include<iostream>
#include<cmath>
using namespace std;
int main()
{  //ax^2+bx+c=0
	double a, b, c, x, d; // d is the discriminant
	char ponovo;// this variable is for the looping
	do{
	cout<<"*******************************"<<endl;
	cout<<"* Izracun kvadratne jednadzbe *"<<endl;
	cout<<"*******************************\n\n";
	cout<<"Ovaj program sluzi za provjeru "<<endl;
	cout<<"Ovaj program sluzi za."<<endl;
	cout<<"Ona je ovog oblika:\n\n";
	cout<<"*** ax^2+bx+c=0 ***\n\n";
	cout<<"Slovo (x) predstavlja nepoznanicu."<<endl;
	cout<<"Slovo (a) predstavlja broj koji mnozi ."<<endl;
	cout<<"Slovo (b) predstavlja broj koji mnozi nepoznanicu."<<endl;
	cout<<"Slovo (c) predstavlja slobodni clan.\n\n";
	cout<<"NAPOMENA: Program radi ispravno samo za pot."<<endl;
	cout<<"Unesite SAMO brojeve, ako unesete s"<<endl;
	cout<<"Unesite broj (a):";
	cin>>a;
	cout<<"Unesite broj (b):";
	cin>>b;
	cout<<"Unesite broj (c):";
	cin>>c;
	cout<<endl;
	cout<<"Unijeli ste jednadzbu:\n\n";
	cout<<"*** ("<<a<<")x^2+("<<b<<")x+("<<c<<")=0 ***\n\n";
	d=pow(b,2.0)-4*a*c; //calculation starts here
	if(d>0){
		cout<<"Diskriminanta jednadzbe je veci od 0"<<endl;
		cout<<"To znaci da jednadzba ima 2 rjesenja."<<endl;
		x=((-1)*b+sqrt(d))/(2*a);
		cout<<"x1="<<x<<endl;
		x=0;
		x=((-1)*b-sqrt(d))/(2*a);
		cout<<"x2="<<x<<endl;}
	if(d==0){
		cout<<"Diskriminanta jednadzbe je jednak 0"<<endl;
		cout<<"To znaci da jednadzba ima 1 rjesenje."<<endl;
		x=((-1)*b)/(2*a);
		cout<<"x="<<x<<endl;}
	if(d<0){
		cout<<"Diskriminanta jednadzbe je manji od 0"<<endl;
		cout<<"To znaci da jednadzba nema realno rjesenje."<<endl;}
	cout<<endl;
	cout<<"Ako zelite ponoviti unesite slo"<<endl;
	cout<<"Ako nezelite ponoviti, unesite bilo"<<endl;
	cout<<"Unesite slovo: ";
	ponovo='n'; // makes sure there is no endless loop ifnon-numbere is entered
	cin>>ponovo;// user decides to repeat or not
	if(ponovo=='d')
		cout<<"\n\n";
	}while(ponovo=='d'||ponovo=='D');
return 0;
}


i cut some strings so it fits better
oops, i'm mean helios.. i wanna know why his program crashes.. void main?
Last edited on
a is not being checked to make sure it's not zero. The program probably threw a division by zero exception.
@helios
uh yes, thx
Topic archived. No new replies allowed.
Pages: 123