Thread: writing the pseudocode........functions

  1. #1
    Registered User
    Join Date
    Apr 2005
    Location
    Barbados
    Posts
    3

    Post 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 ....but i not sure what's expected in this ipo chart...........help?

  2. #2
    Registered User
    Join Date
    Apr 2005
    Location
    Barbados
    Posts
    3
    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

  3. #3
    Registered User Scribbler's Avatar
    Join Date
    Sep 2004
    Location
    Aurora CO
    Posts
    266
    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.
    Last edited by Scribbler; 04-03-2005 at 08:46 AM.

  4. #4
    Registered User
    Join Date
    Apr 2005
    Location
    Barbados
    Posts
    3
    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...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Where to put local auxiliary functions?
    By draugr in forum C++ Programming
    Replies: 10
    Last Post: 03-17-2009, 08:46 PM
  2. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 07:05 PM
  3. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  4. newb question about interpreting and writing functions
    By crazychile in forum C Programming
    Replies: 1
    Last Post: 10-23-2008, 07:51 PM
  5. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM