Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

C++ HELP!


ghost's Avatar
0 0
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
    string username, pass, rite, ritepass;
    ritepass = "orjuela";
    rite = "sergio";
    cout << "enter username: ";
    cin >> username;
    cout << "enter password: ";
    cin >> pass;

    if (username == rite && pass == ritepass)
    {
       cout << "welcome ";
    }
    if (username ! rite) || (pass ! ritepass)
    {
       cout << "try again";
    }
return 0;
}```

Can anyone tell me whats wrong with this?

spyware's Avatar
Banned
0 0

I know! I know! You spelled "right" wrong!

Oh, and you didn't post your errors.


ghost's Avatar
0 0

my errors :(

C:\Documents and Settings\Sergio\Desktop\c++\username.cpp In function `int main(int, char**)':

19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `)' before '!' token

19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp could not convert username' to bool'

19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected primary-expression before '||' token

19 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `)' before '!' token

23 C:\Documents and Settings\Sergio\Desktop\c++\username.cpp expected `;' before "return"


Renaming "rite" wont work :(


spyware's Avatar
Banned
0 0

Yes, well, you pretty much gave it away right there didn't you? Kind of spoiled the challenge for us. I say, go with your conclusions, might lead you to some treasure.

Don't you just love treasure.


ghost's Avatar
0 0
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
    string username, pass, rite, ritepass;
    ritepass = "orjuela";
    rite = "sergio";
    cout << "enter username: ";
    cin >> username;
    cout << "enter password: ";
    cin >> pass;

    if (username == rite && pass == ritepass)
    {
       cout << "welcome ";
    }

return 0;
}

I deleted the bottom part, ran it then i got no errors but when i entered the "rite' username and password nothing happed it just closed. Someone please help me this is very frustrating!


spyware's Avatar
Banned
0 0

IF you only had the answer.

IF only…


ghost's Avatar
0 0

Your not helping……


SET's Avatar

SET

Peumonoultramicroscopicsilico
0 0

In the if statment put a system("pause"); after welcome


spyware's Avatar
Banned
0 0

SET wrote: In the if statment put a system("pause"); after welcome

Using the System command will make this unusable on anything different than a windows-machine.

Also, try to use the ELSE switch instead using IF twice.


ghost's Avatar
0 0

YESS!!!!!!!!!!!! it worked THANKS!

edit:

both of you "pwn"


SET's Avatar

SET

Peumonoultramicroscopicsilico
0 0

Sorry lol spy i always assume ppl use windows michines. STUPID NOOB I AM


spyware's Avatar
Banned
0 0

SET wrote: Sorry lol spy i always assume ppl use windows michines. STUPID NOOB I AM

Of course not. I hope that was sarcasm. You pwn.


ghost's Avatar
0 0

obviously this post is done with good job guys only 13 posts till answered. :)


mido's Avatar
Member
0 0

SET wrote: In the if statment put a system("pause"); after welcome

If you wanted it to pause (or in a programming way : wait for key strokes), you can use one of the following functions : getch(), getche() or getchar().

And this is the right code for what you posted (or at least, cleaned from errors) :

#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
string username, pass, rite, ritepass;
ritepass = "orjuela";
rite = "sergio";
cout << "enter username: ";
cin >> username;
cout << "enter password: ";
cin >> pass;
if (username == rite && pass == ritepass)
{
cout << "welcome ";
}
if (username != rite || pass != ritepass)
{
cout << "try again";
}
return 0;
}


ghost's Avatar
0 0

i dont rly know if this can help but i made my own in ANSI/ISO model my problem is that when it come to the if and else part it dont look like to work.. but a least this code is clear from error :)

#include <iostream>
#include <string>

using namespace std;

int main()
{
	string username, password, lol, loltest;
	username = lol;
	password = loltest;
	std::cout << " Enter your Username\n";
	std::cin >> username;
	std::cout << "Enter your Password\n";
	std::cin >> password;
	if (username == lol && password == loltest)
		{
			std::cout << "welcome\n";
			return 0;
		}
	else
		{
			std::cout << "try again\n";
			return 0;
		}
}

ghost's Avatar
0 0

Crypto, what is the use of writing this

markupusing namespace std; when you are going to do this?

markupstd::cout

edit:

Is this what you were trying to do? I did not understand what your program was meant to do.

#include <iostream>

int main()
{
string username, password;

std::cout << "Enter your Username:";
std::cin >> username;
std::cout << endl;

std::cout << "Enter your Password:";
std::cin >> password;
std::cout << endl;

if (username == "lol" && password == "loltest")
{
std::cout << "welcome\n";
}
else
{
std::cout << "try again\n";
}

getchar();
return 0;
}


ghost's Avatar
0 0

in case you didnt get what everyone is saying here is what your end code should look like (based on suggestions)

#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { string username, pass, rite, ritepass; ritepass = "orjuela"; rite = "sergio"; cout << "enter username: "; cin >> username; cout << "enter password: "; cin >> pass;

if (username == rite && pass == ritepass) { cout << "welcome " << endl; } else { cout << "Wrong" << endl; } system("PAUSE"); return 0; }

good luck


mido's Avatar
Member
0 0

daniel11us wrote: in case you didnt get what everyone is saying here is what your end code should look like (based on suggestions)

#include <cstdio> #include <cstdlib> #include <iostream> using namespace std; int main(int nNumberofArgs, char* pszArgs[]) { string username, pass, rite, ritepass; ritepass = "orjuela"; rite = "sergio"; cout << "enter username: "; cin >> username; cout << "enter password: "; cin >> pass;

if (username == rite && pass == ritepass) { cout << "welcome " << endl; } else { cout << "Wrong" << endl; } system("PAUSE"); return 0; }

good luck

Guys… As I said, getch() would be much better, you can use it on different platforms, also without the "Press any key to continue…" string…

And I HAVE posted the working code, so no need to confuse the guy with namespaces, and shits! Case Closed.


yours31f's Avatar
Retired
10 0

easy way to avoid system("pause");

make a batch file with a pause command