Include other cpp files into main.

I am currently creating a simple login system for an upcoming assignment.
I want to neatly organize everything and have decided to create 2 cpp files with a header to link the two. The problem is when I run the program the command prompt pops up with nothing in it.

Below is the Login 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
#include "stdafx.h"
#include <iostream> 
#include <string>
#include "Login.h"

using namespace std;

void Login()
{
	

	cout << "Welcome, please select one of the following options." << endl;
	cout << "1) Staff \n2) User \n3) Exit" << endl;

	int choose;
	cin >> choose;

	if (choose == 1)
	{
		bool isLogin(); // redirect to isLogin
	}	
	else if (choose == 2)
	{
		cout << "hey";
	}
}


void Login::isLogin()
{

	string username;
	string password;

	cout << "Enter Username: ";
	cin >> username;
	cout << "Enter Password: ";
	cin >> password;

	if (username == "admin" && password == "admin")
	{
		cout << "Work";
	}

}



Below is main.

1
2
3
4
5
6
7
8
#include "Login.h"

int main()
{

	void Login();
}


What exactly am I doing wrong here? I've also tried adding
void Login::isLogin() under void Login() but that does't work.
Last edited on
Your main function does nothing. Line 6 is simply a function declaration (and, presumably, duplicates the declaration that's in "Login.h". It is not a function call.
Last edited on
I see, well I removed void and simply wrote Login(); yet nothing happens. I've looked at a couple of other examples of function calls and I'm doing the same thing. I don't understand what I'm doing wrong
I've managed to do it by creating a Login constructor, then writing Login::Login(), and finally calling it from main()
Do you have Java experience? This looks and feels like someone thinking in Java, but writing in C++.

There's no need to use classes for this simple program.
You've made the same mistake in line 20 of your first code block - you have a function declaration, not a function call.

Is that Login() function defined in lines 8 - 26 supposed to be a constructor for a Login class? Because as it's written there, it's a standalone function.
Topic archived. No new replies allowed.