|
Right this will be my first C++ Programme. I would like to create a programm that will ask the user for a pass number and then if they give the correct pass number, they will be able to se the files (or atleaset Bring up the files) and if they have got the number wrong, then it will write it to a log.
so far I have created an "if" statment, so that when the user enters "23" it says "{cout<<"you got it right, welcome to my Files\n";" and if they get it wrong it writes it to a file but the file only writes it once
What I would Like to know is how do I get it that when the user enters the correct number it will bring up the files in windows, like say "My Documents" or just issue a command into Command Prompt.
here is the Code:
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Please enter pass number: ";
cin>> thisisanumber;
cin.ignore();
if ( thisisanumber == 23 ) {cout<<"you got it right, welcome to my Files\n";
}
else if ( thisisanumber != 23 ) {
cout<<"Denied!\n"; {
ofstream myfile ("/forum/example.txt");
if (myfile.is_open())
{
myfile << "" << thisisanumber << " is not the Number!\n";
myfile << "Atempt Denied\n";
myfile << "--------------\n";
myfile.close();
}
else cout << "Unable to open file"; }
}
cin.get();
return 0;
}
|
|
Thanks for reading,
Pete
<Added>
#include <iostream>
#include <fstream>
using namespace std;
int main()
{
int thisisanumber;
cout<<"Please enter pass number: ";
cin>> thisisanumber;
cin.ignore();
if ( thisisanumber == 23 ) {cout<<"you got it right, welcome to my Files\n"; // this is where i would like it to issue a command promt command, if that is possible
}
else if ( thisisanumber != 23 ) {
cout<<"Denied!\n"; {
ofstream myfile ("/forum/example.txt");
if (myfile.is_open())
{
myfile << "" << thisisanumber << " is not the Number!\n";
myfile << "Atempt Denied\n";
myfile << "--------------\n";
myfile.close();
}
else cout << "Unable to open file"; }
}
cin.get();
return 0;
}
|
|
<Added>
I am useing Dev-C++ Beta
|
|
|
|
|
|
|
|