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

22nd Oct 2020, 10:34 PM
Alpha Zero
Alpha Zero - avatar
7 Answers
+ 1
Hi use your feed or a thread like this one to post challenges https://www.sololearn.com/Discuss/1270852/?ref=app
22nd Oct 2020, 10:38 PM
Abhay
Abhay - avatar
+ 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; }
23rd Oct 2020, 1:59 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 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; }
23rd Oct 2020, 11:03 AM
Alpha Zero
Alpha Zero - avatar
0
NO
23rd Oct 2020, 1:30 AM
SappyB
SappyB - avatar
0
You code will give errors it looking incomplete. What is account admin("admin","12345")
23rd Oct 2020, 1:33 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
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
23rd Oct 2020, 1:39 AM
Alpha Zero
Alpha Zero - avatar
0
"without changing anything in the fonction "
23rd Oct 2020, 2:00 AM
Alpha Zero
Alpha Zero - avatar