jumping into c++

i just got d book jumping into c++ and am finding it hard to get by the practice problems...please who can help out
Last edited on
Hiya, I also have a book and am getting into programming. Is your books first assignment called "Hello world" by any chance?
If you want we can help teach each other?
I have skype or msn.
If you've been reading carefully then you won't be having a hard time understanding how to solve problems, however, if you need help then you're in the right place, post you problem and show your attempt. Many C++ users on this forum would be glad to help you.
this is the program am having a problem with...

Expand the password checking program from earlier in this chapter and make it take multiple
usernames, each with their own password, and ensure that the right username is used for the
right password. Provide the ability to prompt user's again if the first login attempt failed. Think
about how easy (or hard) it is to do this for a lot of usernames and passwords. i dont knw if am on d right track with that code.

<code>

#include <iostream>
#include <string>
using namespace std;
int main ()
{
int i,m;
string username[i],password[i];
string username1;
cout <<"Enter the number of username u want to input: ";
cin >> m;
for (i=0; i<m; i++)
{
cout <<"Enter your username and password"<<endl;
cout << "username:";
cin >>username[i];
cout <<"password: ";
cin >>password[i];
}
cout <<"re-enter your username and password"<<endl;
cout <<"Username: ";
cin >> username1;
</code>
I suggest you read again from variables, arrays and how they are initialized etc.. just read and read and i'm sure you will get it.


That exercise program makes me want to go back again the first days i am learning the basics and so i make my own:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <string>

using namespace std;

int main()
{
    const int MAX_NO_OF_ENTRY = 2;
    
    string user[MAX_NO_OF_ENTRY];
    string pass[MAX_NO_OF_ENTRY];
/*****************************************************
 *  If i'm not mistaken, you cannot initialize the size
 * of an array at runtime w/o dynamic memory allocation
 * and so the code below won't work:
    
    cout << "Enter how many sets of user & pass you want: ";
    cin >> MAX_NO_OF_ENTRY;
    
    string user[MAX_NO_OF_ENTRY];
    string pass[MAX_NO_OF_ENTRY]; 
**********************************************************/
    
    for ( int i = 0; i < MAX_NO_OF_ENTRY; i++ ) {
        cout << "Enter usename for person " << i << endl;
        cin >> user[i];
        
        cout << "Enter password for person " << i << endl;
        cin >> pass[i];
    }
    cout <<"====================================" << endl;
    for ( int i = 0; i < MAX_NO_OF_ENTRY; i++ ) {
        cout << "User " << i+1 << endl;
        cout << "Username: " << user[i] << endl;
        cout << "Password: " << pass[i] << endl << endl;
    }
    
    return 0;
}

This code shows the basic way on how you can solve the problem, i hope this helped a little
@chiebuka39

Take a look here. I think it's a little easier for the first steps...and not only! ;)

http://www.learncpp.com/
Last edited on
Well you have to use logical expressions, like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#include<iostream>
#include<string>
using namespace std;

int main()
{

string username;
string password;
bool success;
do
{
cout<<"Enter your username: ";
cin>>username;
cout<<"Enter your password: ";
cin>>password;

if ( username == "uk" && password == "marine" )
{
success = true;
cout<<"Welcome Uk Marine\n";
}
else if ( username == "guest" || password == "guest" )
{
success = true;
cout<<"Welcome Guest\n";
}
else
{
success = false;
cout<<"Wrong username or password - Please try again\n";
}
} while ( !success );
return 0;
}


- I have read Alex Allain's book, he's a good teacher, but his practice problems are very very challenging especially for someone who's just 'jumping' into C++, it's ok to skip few problems and go back to them later.
Topic archived. No new replies allowed.