c++ - How to create an inverted triangle using only loops/control statements and two cout statements: one that outputs '#' and one that outputs '\n' -
the output supposed follows:
######## ###### #### ##
i have solved issue dropping 2 cout statements constraint:
#include <iostream> void main(){ int starthash = 8; for(int row = 1; row <= 4; row++){ for(int hashnum = 1; hashnum <= starthash; hashnum++){ std::cout << "#"; } std::cout << "\n "; if(row == 2) std::cout << " "; if(row == 3) std:: cout << " "; if(row == 4) std:: cout << " "; starthash -= 2; } system("pause"); }
however, @ point can't figure out how make shape without being able output space, since cout starts @ far left , moves right. appreciated.
notice how spaces in ifs getting longer:
if(row == 2) std::cout << " "; if(row == 3) std:: cout << " "; if(row == 4) std:: cout << " ";
it seems there pattern there, see if can find it. ;-)
(seeing how has 100% chance of being homework question, work it.)
Comments
Post a Comment