Need a little help with pseudocode

  • Thread starter Thread starter bsheltonihs
  • Start date Start date
Click For Summary

Discussion Overview

The discussion revolves around writing pseudocode for a nested For loop to generate a multiplication table from 1*1 to 10*10, specifically focusing on the correct implementation of a new line after every ten outputs. The scope includes programming concepts and pseudocode conventions.

Discussion Character

  • Homework-related
  • Technical explanation
  • Conceptual clarification

Main Points Raised

  • Brad presents a pseudocode attempt and inquires about the correctness of his "new line" statement.
  • One participant suggests that the placement of the new line seems appropriate and encourages experimentation with the code.
  • Another participant notes that while the pseudocode is not strictly C++ or C#, it is acceptable to use a higher-level description and that the "write newline()" statement is acceptable.
  • Brad clarifies that he is working on pseudocode for a C++ class and contrasts it with C# syntax.
  • A participant explains that in C++, newline can be represented by "\n" or by using endl with cout, but emphasizes that pseudocode should focus on algorithm description rather than specific language syntax.

Areas of Agreement / Disagreement

Participants generally agree on the appropriateness of the pseudocode structure, but there is no consensus on the best way to represent new lines in pseudocode, as different interpretations of pseudocode conventions are presented.

Contextual Notes

There is a lack of clarity on the formal conventions for pseudocode, as participants reference different programming languages and their syntax, which may lead to varying interpretations of what constitutes correct pseudocode.

Who May Find This Useful

Students learning programming concepts, particularly those interested in pseudocode and its application in algorithm design.

bsheltonihs
Messages
3
Reaction score
0
I am trying to write a nested For loop to display multiplication table from 1*1 to 10*10 but I need to output a new line after 10 items. I have this written so far and was wondering if my "new line" statement was correct.

Declare nb1, nb2 As Int
For (nb1 = 1; nb1 < 11; nb1++)
For (nb2 =1; nb2 < 11; nb2++)
Write nb1 * nb2 + " "
End For
Write newline( )
End For

Thanks for your help!
Brad
 
Physics news on Phys.org
Outputting the blank line seems to be in the right place. You'll learn a lot more by "trying and seeing" for yourself than by having someone look over it. Do you have a programming language for which you can try this out?

I wonder are there any online sites where a short program can be run? Anybody know?

As your programs get larger and more complicated, it will help comprehension (and reveal some mistakes) if you get into the habit of indenting individual blocks of code, to wit:
Code:
Declare nb1, nb2 As Int
For (nb1 = 1; nb1 < 11; nb1++)
    For (nb2 =1; nb2 < 11; nb2++)
        Write nb1 * nb2 + " "
    End For
    Write newline( )
End For

For the task at hand, you might need to add more detail to your line:
Code:
Write nb1 * nb2 + " "
 
It for a Prelude to programming class for C++. I know that for C# this below would be correct but I just was unsure of the correct way for pseudocode for C++ on how to correctly create a new line. I have looked over my textbook and on the web and i have found nothing on creating a new line in pseudocode. So I took what i found and what i know to come up with the (Write newline " ").

for (int i = 1; i < 11; i++)
{
for(int j=1; j < 11; j++)
{
Console.Write( j * i + " ");
}
Console.Writeline();
}
 
In C++, you can either use the newline character "\n" or you can pass endl to cout:
Code:
cout << "some text" << endl;
// or
cout << "something\n";

For psuedocode, however, you generally don't want to actually write C++ code (or C# for that matter!), but rather a higher level description of the algorithm. You can borrow from a language's syntax, but really the way you write it is up to you, so the "write newline()" statement is fine.
 
Ok thanks for the help everyone!
 

Similar threads

Replies
7
Views
3K
  • · Replies 3 ·
Replies
3
Views
3K
Replies
1
Views
4K
  • · Replies 17 ·
Replies
17
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 6 ·
Replies
6
Views
5K
  • · Replies 7 ·
Replies
7
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
6K