nagantman

Honorable
Dec 7, 2012
3
0
10,510
Hello everyone I just started getting into C++ programming. I am running Ubuntu 12.04, and using the Vim text editor from the Terminal. Currently I am following a guide, that starts with the most basic of writing code. I was just hoping if anyone could give me any pointers when it comes to programming in general, but specifically C++. Thank you.
 

Sunius

Distinguished
Dec 19, 2010
390
0
19,060
Anything you'd like to specifically know? Your question is very abstract, similar to "give me some math tips", and without knowing your level or seeing your code, we cannot give you a good answer.
 

nagantman

Honorable
Dec 7, 2012
3
0
10,510
[cpp]#include <iostream>
#include <string>

using namespace std;

int main ()
{
string username;
string password;
cout << "Enter your username: " << "\n";
getline( cin, username, '\n' );

cout << "Enter your password: " << "\n";
getline( cin, password, '\n' );
if ( username == "root" && password == "xyzzy" )
{
cout << "Access allowed" << "\n";
}
else
{
cout << "Bad username or password. Denied access!" << "\n";
return 0;
}

}[/cpp]
That is the latest program I have written. I'm just not sure about certain things like how to incorporate basic mathematics into the code. Things along those lines like I said, I just started.
 

sevacallDOTcom

Honorable
Dec 11, 2012
3
0
10,510
You can perform basic mathematical operations using operators such as the addition (+), subtraction (-), multiplication (*), division (/), modulus (%)

For example,
a = 2;
b = 6;

cout << a + b;

However, if you'd like to perform more advanced mathematical operations, you'll want to import the math library (#include <cmath>).
 

calmstateofmind

Distinguished
Jul 2, 2009
292
0
19,010
If you want to expand this program, you could put everything in a while loop, and set the controlling variable to a false boolean value, until the correct username and password is entered. This would allow for the user to get multiple attempts of logging in, and you could also install a counter to track the # of times a user attempts to login (+1 for each time they go through the while loop), and after "x" attempts, the program terminates.

That would be the next step, I would say. I can write the code, but I think it would be good for you to tackle this one blind first. It's all within your capabilities. Let me know how it goes!
 

nagantman

Honorable
Dec 7, 2012
3
0
10,510

You say it is all in my capabilities yet I have no idea where to start xD. I don't know how to install a counter or how to set the controlling variable to a false boolean value. I'm all about trying new things, but I just don't know how to write it :|