Solving Algorithm Homework: PrintSpaces(j+1) Error?

  • Thread starter Thread starter Ronaldo95163
  • Start date Start date
  • Tags Tags
    Algorithm
Click For Summary

Discussion Overview

The discussion revolves around a homework problem related to an algorithm that involves a function called printSpaces(j+1). Participants are trying to understand how to handle the variable j, which is not defined in the problem statement.

Discussion Character

  • Homework-related

Main Points Raised

  • One participant expresses confusion about how to execute printSpaces(j+1) without a defined value for j.
  • Another participant suggests that there may be an error in the algorithm unless the programming language in question initializes variables automatically.
  • A different participant proposes assuming that j starts at 0 to proceed with the solution, providing an example output based on this assumption.
  • Subsequent replies confirm the output based on the assumption of j being 0, indicating satisfaction with this approach.

Areas of Agreement / Disagreement

Participants seem to agree on the approach of assuming a starting value for j, but there is no consensus on whether the original question contains an error or if the initialization behavior of the programming language is relevant.

Contextual Notes

The discussion does not clarify whether the assumption about j's initialization is universally applicable across different programming languages or contexts.

Ronaldo95163
Messages
77
Reaction score
1

Homework Statement


In the given picture below


The Attempt at a Solution




Im stuck after the begin
How can I carry out the printSpaces(j+1) if the value of j wasn't given?

Is there an error in the question or is there something that I am not seeing :/
 

Attachments

  • trace.png
    trace.png
    70.9 KB · Views: 523
Physics news on Phys.org
Looks like an error in the given algorithm unless the language automatically initializes all new variables to zero (or some other specified value).

If not defining j was an oversight on the question composer's part then you might state some assumed value for it and proceed to solve the problem using that value.
 
Thanks man

So if I assume that j starts at 0 the output would be:

-*--------*
***********
 
Ronaldo95163 said:
Thanks man

So if I assume that j starts at 0 the output would be:

-*--------*
***********

Looks right to me!
 
Thanks a lot man
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
3K
Replies
1
Views
2K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
Replies
1
Views
2K
Replies
20
Views
4K