Hi,
mabele wrote: |
---|
Now i want to write a pseudo code for above code. How to do it ? |
Pseudo code, is normally written
before one writes their program code. It is a most basic method of designing your project.
It's purpose is to help one write code, by putting down general ideas of what you want to do, in order. Then go back and flesh out those ideas with more detail until one is happy to convert that to code. It can help identify what needs to be in functions, and what can be put into loops.
It's a good idea to do this with comments in your file, leave the comments in after you write the code - they could serve as a form of documentation. Although one should aim to use meaningful variable & function names to result in self documenting code.
tscott8706's post could be seen as a description of what to do. Pseudo code might look like this:
1 2 3
|
input variable a
validate variable a
print variable a
|
You can write whatever you want, we know that we could use
std::cin
and
std:: cout
, but in our pseudo code we use input and print because it is simple and we know what it means.
Be careful when equating floats or doubles - they are not represented exactly and cannot represent every real number, so using the equality operator will almost never work. Instead check to see if the difference between the 2 variables is less than some arbitrary precision value like
0.001
say. However it will work if the user enters the same numbers. I am just pointing this out because it won't work in a majority of other situations.
The default type for floating point in C++ is
double
, prefer that over floats. It is very easy to go past the precision available to a float, they can only do 7 or 8 significant figures, whereas a double can do 15 or 16.
Another Golden Rule is to always initialise your variables to something, preferably on the same line as the declaration of the variable. Do 1 variable per line, with a comment if necessary. Comments can specify expected ranges of values.
Always validate the values that are input, what if the user put in a negative value? Did you check to see if the sum of 2 of the sides is larger than the other one - if not, it's not a triangle. Try to always be mindful of what can go wrong.
Hope all is well