I have a rather simple problem, because I suck at C++

I have no idea what is wrong... Anyone mind reposting on how to fix this because I suck at C++ and want to have 2 things going on at once in my passworded file-retriever. Basically I have burried a file EXTREMELY DEEP in my computer, and I made this program to retrieve it when I need it, under lock and key, so if the correct password is inputted, it opens the file, and if the wrong password is inputted, it closes that program. Just some simple stuff to keep my friends out of my "work". (And to all of you smart-asses out there, no I am not hiding porn)
Here is the code that I have so far:


#include <iostream>
#include <string>
#include <fstream>
using namespace std;

int main()
{
const string passwd("asshat");
string input_passwd;
cout << "Please enter your password: ";
cin >> input_passwd;
if (input_passwd == passwd)
cout << "\nPassword matches!\n";

else (input_passwd == passwd)
ifstream minecraftbeach;
minecraftbeach.open;
if (minecraftbeach.is_open())
{ return 0 }


else
cout << "\nSorry! Wrong password!\n";
return 0
}

Thanks to the answers that I wish to receive,
-Adolf Hipster
When you try to open a file, you need to provide the name of the file.


else (input_passwd == passwd) This doesn't do anything. What's it meant to do? Is there a missing if?

{ return 0 } should be { return 0; } Likewise the other return.
Last edited on
I wanted the ifstream to work if the else was triggered. The else is attached to the if 3 lines up, oh and I fixed the semi-colons, thanks!

Sincerely,
-Adolf Hipster
I wanted the ifstream to work if the else was triggered.


Then possibly you meant this? Note that ( is not the same as {, and that wrapping you if and else blocks in { } is a very good idea, as it means you make it obvious what you actually meant to happen.

1
2
3
4
5
6
7
8
9
10
11
if (input_passwd == passwd)
{
  cout << "\nPassword matches!\n";
}
else
{
  ifstream minecraftbeach;
  minecraftbeach.open; // This line is still totally wrong
}
if (minecraftbeach.is_open())
{ return 0 }


Last edited on
Topic archived. No new replies allowed.