My dev c++ keeps crashing

So i was typing my code about this payment center using classes, throughout my run i managed to fix the compiler error and once there was no more compiler errors, everytime i run my program and when it reaches the part where it displays the information entered it suddenly crashes. i dont have any idea what might be causing this. i am a newbie at programming btw and i am using Dev C++ (the one with the blue icon)
i am using windows 10 64bit(in case this info is necessary) i basically need to know whats causing this and how to fix it :(

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
   #include <iostream>//i/o
#include <cmath>//math expressions
#include <iomanip>//i/o manipulations
#include <string>//string values
#include <fstream>//to read from a file
const double waterrate=17.63; //php per cu.m
const double elecrate=8.1081729;//php per kWh
using namespace std;
class info
{
	protected:
	string Lname;
	string Fname;
	string branch;
	string add;
	public:
	string userinfo()
	{
		
		cout<<"\nenter User first name and last name:";
		cin>>Fname>>Lname;
		cout<<"\nEnter from which branch you are paying: ";
		cin>>branch;
		cout<<"\nEnter your Home address: ";
		cin>>add;
		
		}	
	void displayUser()
	{
		cout<<"\nUser name:\t"<<Fname<<" "<<Lname<<endl;
		cout<<"\nPayment Branch: "<<branch<<endl;
		cout<<"\nUser Address: "<<add<<endl;
		
	}
};

class waterbill//inputs and compus of water
{
	private:
		double prevmetrRead, currntmetrRead;
		public:
		double wamnt;
		
	public:
		double wcost()
		{
			cout<<"enter your previous water reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			wamnt=abs(prevmetrRead-currntmetrRead)*waterrate;
			cout<<"your total water balance is : "<<wamnt<<" "<<"php"<<endl;
			
		}
};

class electricbill//input and compus of electric bill
{
	private:
	double prevmetrRead, currntmetrRead;
	public:
	double eamnt;
	public:
		double ecost()
		{
			cout<<"enter your previous Electricity reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			eamnt=abs(prevmetrRead-currntmetrRead)*elecrate;
			cout<<"your total water balance is : "<<eamnt<<" "<<"php"<<endl;
		}
		
};







int main()//main function
{
	
	info i;
	info j;
	
	i.userinfo();
	j.displayUser();
	
	

	return 0;
}
Last edited on
Functions with a non-void return type should always return a value.
so i am suppose to put at the end of my int main() "return 1;" (like this?)?? i did this and still crashes
Last edited on
Well, you don't have to do it with main() because it's a bit special. I was more thinking of the three functions userinfo(), wcost() and ecost(). If you don't want them to return anything you should change the return type to void.
Last edited on
Just to clarify with what Peter87 already said: Getting user input (via cin) is not the same thing as returning a value from the function itself. Change your function's return type to void if you don't have return some_value; in the function itself.
Last edited on
WOW it was as simple as that thank you sir Peter87 your solution worked heres what i did EDIT: it did stop crashing although now it keeps on repeating the functions that i put those returns to haha i celebrated too early
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <iostream>//i/o
#include <cmath>//math expressions
#include <iomanip>//i/o manipulations
#include <string>//string values
#include <fstream>//to read from a file
const double waterrate=17.63; //php per cu.m
const double elecrate=8.1081729;//php per kWh
using namespace std;
class info
{
	protected:
	string Lname;
	string Fname;
	string branch;
	string add;
	public:
	string userinfo()
	{
		
		cout<<"\nenter User first name and last name:";
		cin>>Fname>>Lname;
		cout<<"\nEnter from which branch you are paying: ";
		cin>>branch;
		cout<<"\nEnter your Home address: ";
		cin>>add;
		
		return userinfo();
		
		}	
	void displayUser()
	{
		cout<<"\nUser name:\t"<<Fname<<" "<<Lname<<endl;
		cout<<"\nPayment Branch: "<<branch<<endl;
		cout<<"\nUser Address: "<<add<<endl;
		
	}
};

class waterbill//inputs and compus of water
{
	private:
		double prevmetrRead, currntmetrRead;
		public:
		double wamnt;
		
	public:
		double wcost()
		{
			cout<<"enter your previous water reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			wamnt=abs(prevmetrRead-currntmetrRead)*waterrate;
			cout<<"your total water balance is : "<<wamnt<<" "<<"php"<<endl;
			
			return wcost();
			
		}
};

class electricbill//input and compus of electric bill
{
	private:
	double prevmetrRead, currntmetrRead;
	public:
	double eamnt;
	public:
		double ecost()
		{
			cout<<"enter your previous Electricity reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			eamnt=abs(prevmetrRead-currntmetrRead)*elecrate;
			cout<<"your total water balance is : "<<eamnt<<" "<<"php"<<endl;
			
			return ecost();
		}
		
};







int main()//main function
{
	
	info i;
	info j;
	
	i.userinfo();
	j.displayUser();
	
	

	return 0;
}
Last edited on
ok so now i did return values but the problem now is that it doesnt display the values anymore, here what i currently have
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include <iostream>//i/o
#include <cmath>//math expressions
#include <iomanip>//i/o manipulations
#include <string>//string values
#include <fstream>//to read from a file
const double waterrate=17.63; //php per cu.m
const double elecrate=8.1081729;//php per kWh
using namespace std;
class info
{
	protected:
	string Lname;
	string Fname;
	string branch;
	string add;
	public:
	string userinfo()
	{

		cout<<"\nenter User first name and last name:";
		cin>>Fname>>Lname;
		cout<<"\nEnter from which branch you are paying: ";
		cin>>branch;
		cout<<"\nEnter your Home address: ";
		cin>>add;

		return Fname;
		return Lname;
		return branch;
		return add;

		}
	void displayUser()
	{
		cout<<"\nUser name:\t"<<Fname<<" "<<Lname<<endl;
		cout<<"\nPayment Branch: "<<branch<<endl;
		cout<<"\nUser Address: "<<add<<endl;

	}
};

class waterbill//inputs and compus of water
{
	private:
		double prevmetrRead, currntmetrRead;
		public:
		double wamnt;

	public:
		double wcost()
		{
			cout<<"enter your previous water reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;

			wamnt=abs(prevmetrRead-currntmetrRead)*waterrate;
			cout<<"your total water balance is : "<<wamnt<<" "<<"php"<<endl;

			return wamnt;

		}
};

class electricbill//input and compus of electric bill
{
	private:
	double prevmetrRead, currntmetrRead;
	public:
	double eamnt;
	public:
		double ecost()
		{
			cout<<"enter your previous Electricity reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;

			eamnt=abs(prevmetrRead-currntmetrRead)*elecrate;
			cout<<"your total water balance is : "<<eamnt<<" "<<"php"<<endl;

			return eamnt;
		}

};







int main()//main function
{

	info i;
	info j;

	i.userinfo();
	j.displayUser();



	return 0;
}
well i managed to find my way around it by removing my displayUser() function and putting it all in the userinfo() function, thanks for the helps. heres the code for reference purposes for those who encounter the same problem i have. cheers!

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include <iostream>//i/o
#include <cmath>//math expressions
#include <iomanip>//i/o manipulations
#include <string>//string values
#include <fstream>//to read from a file
const double waterrate=17.63; //php per cu.m
const double elecrate=8.1081729;//php per kWh
using namespace std;
class info
{
	protected:
	string Lname;
	string Fname;
	string branch;
	string add;
	public:
	string userinfo()
	{
		
		cout<<"\nenter User first name and last name:";
		cin>>Fname>>Lname;
		cout<<"\nEnter from which branch you are paying: ";
		cin>>branch;
		cout<<"\nEnter your Home address: ";
		cin>>add;
		
		cout<<"\nUser name:\t"<<Fname<<" "<<Lname<<endl;
		cout<<"\nPayment Branch: "<<branch<<endl;
		cout<<"\nUser Address: "<<add<<endl;
		
		return Fname;
		return Lname;
		return branch;
		return add;
		
		}	
	/*void info.userinfo()
	{
		cout<<"\nUser name:\t"<<Fname<<" "<<Lname<<endl;
		cout<<"\nPayment Branch: "<<branch<<endl;
		cout<<"\nUser Address: "<<add<<endl;
		
		
	}*/
};

class waterbill//inputs and compus of water
{
	private:
		double prevmetrRead, currntmetrRead;
		public:
		double wamnt;
		
	public:
		double wcost()
		{
			cout<<"enter your previous water reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			wamnt=abs(prevmetrRead-currntmetrRead)*waterrate;
			cout<<"your total water balance is : "<<wamnt<<" "<<"php"<<endl;
			
			
			return wamnt;
		}
};

class electricbill//input and compus of electric bill
{
	private:
	double prevmetrRead, currntmetrRead;
	public:
	double eamnt;
	public:
		double ecost()
		{
			cout<<"enter your previous Electricity reading: ";
			cin>>prevmetrRead;
			cout<<"enter your current water reading: ";
			cin>>currntmetrRead;
			
			eamnt=abs(prevmetrRead-currntmetrRead)*elecrate;
			cout<<"your total water balance is : "<<eamnt<<" "<<"php"<<endl;
			
			return eamnt;
		}
		
};







int main()//main function
{
	
	info i;
	
	
	i.userinfo();
	
	
	

	return 0;
}
Returning has nothing to do with IO (cin/cout).

Just to demonstrate... There is a function called sqrt. When you pass a number as argument it will return the square root of that number. In order for the return value to be useful you need to do something with it, e.g. store it in a variable, use it in a calculation, or pass it as argument to another function. There is no point in calling sqrt if you do not use the returned value for anything.

1
2
3
double a = 5;
double b = sqrt(a);
cout << "The square root of " << a << " is " << b << ".\n";


Sometimes you don't want a function to return any values. Instead you just want it to do something and then return, without returning any value. In this case the return value should be void, which means the function will not return any value back to where the function was called from. I think this is the situation that you had in your original program. Instead of adding those return statements you should simply have changed the return types to void. You already had it right for the displayUser() function.
Last edited on
Topic archived. No new replies allowed.