return 0; a problem out here!!

Please have a look into the code Below...
Using Visual Studio 2013.

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
#include"stdafx.h"
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<string>
#include<dos.h>
#include<Windows.h>

using namespace std;

int loginPass();
void ins();

void wlcscrn()
{
	system("cls");
	cout << "                      Universal Lab           ";
	cout << "\n    ULF VER : 01/01                   15/09/2015";
	Sleep(3000);
}

void loginUser()
{
	system("cls");
	string a, user ="guest";
	cout << "Username - ";
	cin >> a;
	if (a == user)
	{
		cout << "";
	}
	else
	{
		cout << "Incorrect Username";
		loginUser();
	}
}


int loginPass()
{
	int b = 0000, c;
	cout << "Password - ";
	cin >> c;
	if (b != c)
	{
		cout << "Incorrect Password!";
		_getch();
		return 0;
	}
	else
	{
		cout << "Login Successful.";
		_getch();
	}
}
void ins()
{
	system("cls");
	int d = 1, e = 2, f;
	cout << "Insert Tray                            Single - " << d;
	cout << "\nLoad Drum                              Double - " << e;
	cin >> f;
	if (f == d)
		std::cout << "Single";
	else if (f == e)
		std::cout << "Double";
	else
		std::cout << "Invalid Entry";
	_getch();
}

void main()
{
	wlcscrn();
	loginUser();
	loginPass();
	ins();
}



In loginPass function, I want that the Program Ends if Password Entered is WRONG.

When I enter a wrong Password It should End the program... but it goes to ins function...

return 0; doesn't end my program... I'm a complete beginner..
--> Please Help Me and get me solution to this...
I want to End program if password entered is wrong.

\\Apologizes for my bad english...
The return statement only ends the current function. If you have a function with a non-void return type you should always make sure it returns a value. In loginPass() you don't always return a value.

If loginPass() returns 0 when login fails and 1 when it succeeds you could check the return value in main, where you call the function. If the return value is 1 you call the ins() function, otherwise you just let the main function end.
@integralfx

Many thanks to you!!!!

@Peter87

Thanks to make me understand that return 0; would only end my function and not the whole program!!


--> Thanks to both of you!!!
Topic archived. No new replies allowed.