0
C++ Challenge
#include <iostream> int main() { account admin("admin", "12345"); if (true) std::cout << "print garbeg"; if (false) std::cout << admin; } your objective is to adjust the c++ code above to print admin's username and password instead of printing garbage, but you can't change anything inside the main fonction
7 Answers
+ 1
Hi use your feed or a thread like this one to post challenges
https://www.sololearn.com/Discuss/1270852/?ref=app
+ 1
May be you expecting this Output
#include <iostream>
using namespace std;
int main() {
int password=12345;
cout<<"enter password \n";
cin>>password;
if(password==12345)
{
cout<<" you are admin\n";
}
else
{
cout<<"Try to enter again";
}
return 0;
}
+ 1
Solution :
#include <iostream>
#define true 0
#define false 1
struct account
{
std::string username, password;
account(std::string u, std::string p) : username(u), password(p) {}
};
std::ostream & operator << (std::ostream &s, account &a)
{
s << a.username << " " << a.password;
return s;
}
int main()
{
account admin("admin", "12345");
if (true)
std::cout << "print garbeg";
if (false)
std::cout << admin;
}
0
NO
0
You code will give errors it looking incomplete. What is account admin("admin","12345")
0
I know, the goal is to complete it
and print the username and password
print "admin 12345"
instead of "print garbege"
without changing the main fonction
0
"without changing anything in the fonction "