Double "If", "Else"
Oct 6, 2017 at 7:19pm UTC
How to do double "if" and "else" ?
When i do everything correctly or i type wrong "haslo" it doesn't have any errors but when i type wrong login itnsays "Nie ma takiego uzytkownikaBledne haslo" What should i do? Also, sorry for my english ;/
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
#include <iostream>
using namespace std;
string login, haslo;
int main()
{
cout << "Podaj Login: " ;
cin >> login;
if (login=="admin" )
{
cout << "Podaj Haslo: " ;
cin >> haslo;
}
else
cout << "Nie ma takiego uzytkownika" ;
if (haslo=="szarlotka" )
{
cout << "Zalogowales sie!" << endl;
cout << "Dziekujemy za korzystanie z naszego serwisu!" ;
}
else
{
cout << "Bledne haslo" ;
}
Oct 6, 2017 at 7:24pm UTC
Perhaps you mean 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
#include <iostream>
using namespace std;
string login, haslo;
int main()
{
cout << "Podaj Login: " ;
cin >> login;
if (login=="admin" )
{
cout << "Podaj Haslo: " ;
cin >> haslo;
if (haslo=="szarlotka" )
{
cout << "Zalogowales sie!" << endl;
cout << "Dziekujemy za korzystanie z naszego serwisu!" ;
}
else
{
cout << "Bledne haslo" ;
}
}
else
{
cout << "Nie ma takiego uzytkownika" ;
}
Oct 6, 2017 at 7:27pm UTC
Yeah, thanks. :D It was easier than i thought, sorry for taking your time with my n00b questions ;D
Topic archived. No new replies allowed.