Console closing before the end of int_main

Hello Folks!

I just started out with C++, but when I was trying a little, I stumbled across a problem.

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
// Unnamed.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string PASSWORD;
string PASSWORD1;

string MAKE_PASSWORD()
{
	cout << "Please choose a password:" << endl;
	getline(cin,PASSWORD);
	return ();
}

string CONFIRM_PASSWORD()
{
	cout << "Please confirm your password:" << endl;
	getline(cin,PASSWORD1);
		if (PASSWORD1 == PASSWORD)
{
cout <<"Acces Granted!" << endl;
return 0;
		}
		else if (PASSWORD1 != PASSWORD){
cout <<"Acces Denied!" << endl;
return 0;		
		}
	
}




int _tmain(int argc, _TCHAR* argv[])
{
	MAKE_PASSWORD();
	CONFIRM_PASSWORD();
	  cout << "Press ENTER to continue...";
  cin.ignore( numeric_limits<streamsize>::max(), '\n' );

  
}


Something, which I do not know what, causes the program to quit it before reaching the end of the main function.

Thanks In Advance:

Sanguine
Last edited on
Does your code compile?
You messed a bit with function return types, both MAKE_PASSWORD and CONFIRM_PASSWORD should return a string but on one you are returning nothing, on the other you are returning an integer
Oops, didn't notice that :o But my code does compile correctly, without giving an error. So that didn't really fix the problem
Yes, it does give errors:
D:\prog\cc\foo>g++ -Wall -ansi -pedantic a.cpp
a.cpp: In function 'std::string MAKE_PASSWORD()':
a.cpp:16: error: expected primary-expression before ')' token
a.cpp: At global scope:
a.cpp:38: error: '_TCHAR' has not been declared
a.cpp: In function 'int _tmain(int, int**)':
a.cpp:43: error: 'numeric_limits' was not declared in this scope
a.cpp:43: error: expected primary-expression before '>' token
a.cpp:43: error: no matching function for call to 'max()'

Try to avoid non-standard junk.

Only name global CONSTANT objects in all-caps.
You must #include <limits> to use the numeric_limits class and <windows.h> to use TCHAR.
Please don't use "_TCHAR". Use TCHAR.
Your function prototypes should be:
1
2
string get_password();
bool confirm_password( const string& password );

The first should get a password from the user and return it.
The second should get another password from the user and return whether or not it matches the argument.
Main should return 0;

Hope this helps.
I already re-wrote the whole code ^^. But still the strange thing is, in Visual C++ it didnt give any errors :o. But I did learn something from that reply!
Topic archived. No new replies allowed.