How to Solve a Computer Science C++ Problem?

Click For Summary

Discussion Overview

The discussion revolves around solving a C++ programming problem related to using for loops to print a specific pattern. The scope includes technical explanations and peer support for a beginner in C++.

Discussion Character

  • Technical explanation, Homework-related, Exploratory

Main Points Raised

  • One participant suggests modifying the loop condition to correctly print the desired number of spaces and X's.
  • Another participant mentions that using the formula 2*lineCtrl-1 leads to an infinite loop, indicating a potential issue with the logic.
  • A different participant expresses confidence in their solution but encourages the original poster to share their revised code for further feedback.
  • A participant reveals they are new to C++ and requests additional guidance to understand the problem better.
  • Ultimately, the original poster indicates they have resolved their issue independently.

Areas of Agreement / Disagreement

The discussion includes varying perspectives on the correct implementation of the code, with some participants providing suggestions while others express different experiences. The original poster's final resolution indicates a shift in understanding, but no consensus on the initial approach is reached.

Contextual Notes

Participants reference specific coding practices and logic without fully resolving the underlying issues related to loop conditions and output formatting.

Who May Find This Useful

Individuals learning C++ programming, particularly those struggling with loops and pattern printing in an accelerated course setting.

ZincPony
Messages
21
Reaction score
0
Problem Solved thank you
 
Last edited:
Physics news on Phys.org
for (int spaceCtrl = 4; spaceCtrl >=1 ; spaceCtrl--)
This will just print 4 blanks every line. That is you need to change the test condition and associate it with lineCtrl variable.

for (int xCtrl = 1; xCtrl <= lineCtrl; ++xCtrl)
Remember you need 2*lineCtrl-1 X's in each line.
 
doing the 2*lineCtrl-1 send it into an infinite X printing loop.
 
Seems to work fine for me. I am not giving you the code just yet. Why don't you post your revised code? And mind your braces :smile:
 
hey man this is my first C++ class in the summer which means its accelerated. soo he just introduced for loops in wed class soo I am trying to create this from it. I am stumped. can you give me a lil bit of a bigger clue to go from.
 
never mind i figured id it out.

thank you
 

Attachments

  • final.JPG
    final.JPG
    13.4 KB · Views: 429
Last edited:

Similar threads

  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
4
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 20 ·
Replies
20
Views
4K
  • · Replies 41 ·
2
Replies
41
Views
5K