0
How can i controle what the user inputs?
( example: a password : does the user writes abcdef or 123456. i tried it like this : string password;cin >> password;if ( password == string){cout << ...}else if ( password == int){cout << ...} ...
15 ответов
0
Briefly describe what you want to establish!
0
i want that the user inputs a password. but i want that he can write 123456 ( numbers ) and abcdef ( letters )
0
Then you can declare "password" as an array of characters. Then it can be both numbers as well as alphabets. Hope it helps
0
i didnt really understand arrays can you pls explain me how i can do it ?
0
char password[30] ="iLoveC++123";
if(passwords match)
cout<<"access granted";
else cout<<"try again";
Just a sample.
0
how can i output the array completely ?
if i have an array :
char a [8];
and in a for loop i want the user to input in this a array 8 chars. example : 1 2 3 4 a b c d . the for loop counts this like this:
1: 1
2: 2
3: 3
4: 4
5: a
6: b
7: c
8: d
and now here i want this array comepletely outputted like this :
cout a = 1 2 3 4 a b c d
how can i do it ?
0
Don't use endl in your cout statement
0
got it:
#include <iostream>
using namespace std;
int main() {
char password[8];
cout << "Geben Sie ein 8 - stelliges Passwort ein " << endl;
for (int i = 0; i <= 7; i ++){
cin >> password[i];
}
cout << password;
return 0;
}
0
That should do the job :)
0
now i want to write an if loop which 'couts' something if the password is just from letter ( qwertgfs ) and something else if its just from numbers ( 18382273 ). example
(fail syntax i want to know the right)
if ( password == int ){
cout << //(example)\* "your password isn't really safe";
}
else if( password == string ) {
cout << //something else
}
this password == string doesnt work how is the right syntax ?
0
You can check every character with isdigit() and when it's all true it's a number if at least one is false it's a string
0
dont works like this: (password is a char datatype variable and already decleared)
if (password = isdigit()){
cout << "wow" ;
}
0
No, Peter. isdigit(char value) returns if it is a number or not. apply them to all the characters in the string.
0
works
#include <iostream>
using namespace std;
int main() {
char x;
cin >> x;
if(isdigit(x)){
cout << "number is: "<< x << endl;
}else if (!isdigit(x)){
cout << "isn't a number fgt";
}
return 0;
}
0
#include <iostream>
using namespace std;
int main() {
char x[8];
cout << "Put a Password with 8 letters/numbers" << endl;
// x = Password
for (int i = 0; i <= 7; i ++){
cin >> x[i];
}
cout << x;
if (isdigit(x)){
cout << "Your Password isn't really safe. It includes just numbers." ;
// Doesn't matter if just numbers, just an information
}
if (!isdigit(x)){
cout << "Success: Password has been created"; << endl;
}
return 0;
}
what is the problem ?
always error : something like
unvalid change of char* to int