Sign in with
Sign up | Sign in
Your question

New to C++

Last response: in Applications
Share
December 13, 2012 9:03:01 PM

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.

More about : question

a b L Programming
December 13, 2012 9:04:21 PM

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.
m
0
l
December 13, 2012 9:14:06 PM

  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. string username;
  9. string password;
  10. cout << "Enter your username: " << "\n";
  11. getline( cin, username, '\n' );
  12.  
  13. cout << "Enter your password: " << "\n";
  14. getline( cin, password, '\n' );
  15. if ( username == "root" && password == "xyzzy" )
  16. {
  17. cout << "Access allowed" << "\n";
  18. }
  19. else
  20. {
  21. cout << "Bad username or password. Denied access!" << "\n";
  22. return 0;
  23. }
  24.  
  25. }

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.
m
0
l
Related resources
December 13, 2012 10:18:01 PM

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>).
m
0
l
a b L Programming
December 13, 2012 10:37:29 PM

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!
m
0
l
December 13, 2012 11:58:28 PM

calmstateofmind said:
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!

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 :|
m
0
l
a b L Programming
December 14, 2012 5:04:31 AM

You need to follow a good tutorial to get the most put of any programming language. Buy a book or find one online - there are plenty of them. Just Google "C++ tutorial".
m
0
l
!