fork download
  1. //Phil, you need to increment i by two instead of one
  2.  
  3. #include <iostream>
  4.  
  5. int main()
  6. {
  7. int amountOfLoops = 5;
  8. //J is equal to zero because we run the j for loop one more time than i
  9. //(One more time than zero is one)
  10. for(int i=1; i<=amountOfLoops; i+=2)
  11. {
  12. for(int k=1; k<=((amountOfLoops-i) / 2); k++) {
  13. std::cout << " ";
  14. }
  15. for(int j=1; j <= i; j++)
  16. {
  17. std::cout << "X";
  18. }
  19. //Phil, I will use newline rather than std::endl
  20. //std::cout << std::endl;
  21. std::cout << "\n";
  22. }
  23. std::cout << std::endl;
  24. //Phil! Don't use System("pause")! It's platform specific to the Windows
  25. //Operating System and literally pauses the OS. Also, command line programs
  26. //should never have to use System("pause"). If you really need to pause the
  27. //program, use std::cin.get();
  28. //system("pause");
  29. std::cin.get();
  30.  
  31. return 0;
  32. }
Success #stdin #stdout 0s 2856KB
stdin
Standard input is empty
stdout
  X
 XXX
XXXXX