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

  • Thread starter Thread starter Ronaldo95163
  • Start date Start date
  • Tags Tags
    Algorithm
AI Thread Summary
The discussion centers on a homework problem involving the function printSpaces(j+1), where the value of j is not initially defined. Participants express confusion about whether this omission is an error in the question or if the programming language automatically initializes variables. It is suggested that assuming j starts at 0 allows for a valid solution to the problem. The output generated from this assumption appears correct to the contributors. The conversation concludes with a confirmation of the solution based on the assumed value of j.
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: 505
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
 
Back
Top