Beginner cout question
Dec 11, 2009 at 11:11pm UTC
In response to an exercise that asked for a program to print "HELLO" in big block letters where each letter is 7 characters high and 5 characters wide, I coded:
1 2 3 4 5 6 7 8 9 10 11 12
#include <iostream>
int main()
std::cout << "* * ***** * * *****" << "\n" ;
std::cout << "* * * * * * *" << "\n" ;
std::cout << "* * * * * * *" << "\n" ;
std::cout << "***** **** * * * *" << "\n" ;
std::cout << "* * * * * * *" << "\n" ;
std::cout << "* * * * * * *" << "\n" ;
std::cout << "* * ***** ***** ***** *****" << "\n" ;
return (0);
}
It compiled and returned the desired effect, however, I'm wondering if there was a simpler or less redundant method to code this...
Dec 11, 2009 at 11:43pm UTC
You can "chain" the std::couts together like so:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
#include <iostream>
int main()
//no ';' on the end, so that the << works correctly
//the compiler doesn't care about extra enters or spaces
std::cout << "* * ***** * * *****" << "\n"
<< "* * * * * * *" << "\n"
<< "* * * * * * *" << "\n"
<< "***** **** * * * *" << "\n"
<< "* * * * * * *" << "\n"
<< "* * * * * * *" << "\n"
<< "* * ***** ***** ***** *****" << "\n" ;
return (0);
}
Dec 12, 2009 at 12:38am UTC
Thanks! Exactly what I was looking for.
Topic archived. No new replies allowed.