# writing the pseudocode........functions

• 04-02-2005
bajan
writing the pseudocode........functions
have an assign.
have to do an ipo chart.......unsure how to factor in the functions into the algorithm
i have to do both flowchart and pseudocode....... :(

the thing is......i've already written the code :confused: ....but i not sure what's expected in this ipo chart...........help?
• 04-03-2005
bajan
this is my code:
Code:

```#include <iostream> #include <cmath> using namespace std; double add() {         double N1=0.0, N2=0.0, sum;         cout<<"Enter 2 numbers"<<endl;         cin>>N1>>N2;         sum=N1+N2;         return sum; }//end of function add double subtract() {         double N1=0.0,N2=0.0, diff;         cout<<"Enter 2 numbers"<<endl;         cin>>N1>>N2;         diff=N1-N2;         return diff; }//end of function subtract double divide() {         double N1=0.0,N2=0.0,ans;         cout<<"Enter 2 numbers"<<endl;         cin>>N1>>N2;         ans=N1/N2;         return ans; }//end of function divide double multiply() {         double N1=0.0, N2=0.0,prod;         cout<<"Enter 2 numbers"<<endl;         cin>>N1>>N2;         prod=N1*N2;         return prod; }//end of function multiply void compare() {         double N1=0.0,N2=0.0;         cout<<"Enter 2 numbers"<<endl;         cin>>N1>>N2;         if(N1>N2)         {                 cout<<"The 1st number is larger"<<endl;         }         else if(N1<N2)         {                 cout<<"The 2nd number is larger"<<endl;         }         else         {                 cout<<"The numbers are equal"<<endl;         } }//end of function compare float sqrt() {         float SQR=0.0;         cout<<"Enter the number"<<endl;         cin>>SQR;         SQR=sqrt(SQR);         cout<<"The answer is: "<<SQR<<endl;         return SQR; }//end of square root function double power() {         double N1=0.0,N2=0.0,ans;         cout<<"Enter 2 numbers. The second number being the POWER."<<endl;         cin>>N1>>N2;         ans=pow(N1,N2);         cout<<endl<<"The answer is: "<<ans<<endl;         return ans; }//end of function power void menu() {         int choice;                         while(choice!=8)         {                             cout<<"Please choose an operation"<<endl             <<"Press 1 Add"<<endl             <<"Press 2 Subtract"<<endl             <<"Press 3 Divide"<<endl                 <<"Press 4 Multiply"<<endl             <<"Press 5 Compare"<<endl             <<"Press 6 Square root"<<endl             <<"Press 7 Power"<<endl             <<"Press 8 Quit"<<endl;         cin>>choice;                         if(choice==1)         {         cout<<"The answer is:"<<add()<<endl;         }         else if (choice==2)         {         cout<<"The answer is:"<<subtract()<<endl;         }         else if(choice==3)         {         cout<<"The answer is:"<<divide()<<endl;         }         else if (choice==4)         {         cout<<"The answer is:"<<multiply()<<endl;         }         else if (choice==5)         {         compare();         }         else if (choice==6)         {         sqrt();         }         else if (choice==7)         {         power();         }                 else         {                 cout<<"Error in input data"<<endl;         }//end of if         }//end of while         if(choice==8)         {cout<<"Thank you for using my Calculator program."<<endl;}         }//end of menu function```
• 04-03-2005
Scribbler
A small bit of constructive criticism...

Although you can pseudo-code/flowchart your existing code, it would run counter to your assignment. Additionally, I would recommend completely ignoring your current code and pseudo-code / flowchart your menu from scratch. If you do that, I think you'll find a lot of redundant code in your current incarnation (hence the reason for pseudo-coding before authoring to begin with) :).

Hint... focus on learning to pseudo-code switch statements, and passing values to functions, as well as returning values.
• 04-15-2005
bajan
Quote:

Originally Posted by Scribbler
A small bit of constructive criticism...

Although you can pseudo-code/flowchart your existing code, it would run counter to your assignment. Additionally, I would recommend completely ignoring your current code and pseudo-code / flowchart your menu from scratch. If you do that, I think you'll find a lot of redundant code in your current incarnation (hence the reason for pseudo-coding before authoring to begin with) :).

Hint... focus on learning to pseudo-code switch statements, and passing values to functions, as well as returning values.

uh huh...thanx y
u sound like a pro...which i am not.....
far from...