Need a little help with pseudocode

  • Thread starter bsheltonihs
  • Start date
In summary, the conversation was about writing a nested For loop to display a multiplication table from 1*1 to 10*10 in C++. The person was unsure about the correct way to create a new line in pseudocode and was seeking clarification. The use of the "write newline()" statement was deemed appropriate for this task.
  • #1
bsheltonihs
3
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
  • #2
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 + " "
 
  • #3
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();
}
 
  • #4
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.
 
  • #5
Ok thanks for the help everyone!
 

1. What is pseudocode?

Pseudocode is a formal, high-level description of a computer program or algorithm that uses natural language and simple statements to outline the steps or logic of the program. It is not an actual programming language, but rather a tool used to help plan and understand the structure of a program before coding begins.

2. Why is pseudocode useful?

Pseudocode is useful because it allows programmers to think through and plan the logical steps of a program without getting bogged down in the specific syntax of a programming language. It also helps to identify potential issues and errors in the logic before actual coding begins.

3. How do you write pseudocode?

There is no one specific way to write pseudocode, but it generally follows a structure of using simple and understandable language to describe the steps or logic of a program. It may also include variable names, conditional statements, and loops to help illustrate the flow of the program.

4. Can pseudocode be translated into any programming language?

Yes, pseudocode can be translated into any programming language, although some languages may have slight variations in syntax. It is important to note that pseudocode is not meant to be a direct translation, but rather a helpful guide for writing code in a specific language.

5. Is pseudocode necessary for all programming tasks?

No, pseudocode is not necessary for all programming tasks. It can be particularly helpful for complex or large programs, but may not be as necessary for smaller, simpler tasks. Ultimately, the use of pseudocode is up to the discretion of the programmer and their individual coding style.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
12
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
299
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
17
Views
2K
  • Programming and Computer Science
Replies
16
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
4K
Back
Top