Thread: Einstine calculator

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    7

    Talking Einstine calculator

    Hi I've learning to program for about the last 2 years. Any way i found a ZIP disk yesterday and on it was a program I wrote about a year ago, tell me what you think.

    Code:
    
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    /*
    Author :A.Mac Hugh
    Date:-21-10-2002
    Version:*/
    void engery (); /* function prototype*/
    void lenght (); /* function prototype*/
    void time (); /* function prototype*/
    int exit();  /*fuction protoyype*/
    void momentum (); /* function prototype*/
    void mass (); /* function prototype*/
    void Kenetic_Eng (); /* function prototype*/
    void st();
    int menu();
    int exit();
    #define c 3E8
    
    int main()
    {    void menu (); /* function prototype*/
         printf("\n\tWelcome to Machsofts Einstine calculator.\n\tThis program will \n\tcalculate all of the equatios for Einstines Theroy of Special General Relativity.");
    	 printf("\n\tThis is copyright Machsoft INC 2002");
    	 printf("\n\tVersion 1.0 Beta\n\n\n");/* intoduction*/
    
    	 
    	 exit();
    	 menu (); /*fuction beging run*/
    
    }
    
    int menu (){
    int nums;
    /* ask user for therir option*/
    printf("\n\n\n");
    printf("\n\n\nSlect from 1-0 and  hit enter after  choice\n\n");
    printf("\t\tTo calculate Engery  press \t\t\t(1)\n");
    printf("\t\tTo calculate Lenght contraction press \t\t(2)\n");
    printf("\t\tTo calculate Time dialation press \t\t(3)\n");
    printf("\t\tTo calculate Relativistic Momentum \t\t(4)\n");
    printf("\t\tTo calculate Relarive Mass  press \t\t(5)\n");
    printf("\t\tTo calculate Kenetic Engery \t\t\t(6)\n");
    printf("\n\t\t\tTo exit  press (0) then enter\n");
    
    scanf("%d",& nums);/*get option*/
    
     /*Switich statment for chosesing option*/
    switch (nums){
    
    
    case 0:
    exit();
    printf("\n\n)");
    break;
    
    case 1 :
    engery();
    printf("\n\n)");
    break;
    
    case 2:
    lenght();
    printf("\n\n)");
    break;
    
    case 3:
    time();
    printf("\n\n)");
    break;
    
    case 4:
    momentum();
    printf("\n\n)");
    break;
    
    case 5:
    mass();
    printf("\n\n)");
    break;
    
    case 6:
    Kenetic_Eng();
    printf("\n\n)");
    break;
    
    case 1701:
    st();
    printf("\n\n)");
    break;
    
    default:/*invalid option*/
    printf("\aInvaiid Option \n\nEnter choice again \n\n");
    menu();
    printf("\n\n\n\n");
    break;
         }
     
    return 0; }
    
    
    
     /*fuction to exit program*/
    int exit(){
    	 system("PAUSE");
    	 return 0;
          }
    
    /* Fuction name :engery
     
    Fuction varibles( All floats) : e engery
                                    m mass
    				   
    
    Purpose: Ask user to enter in the mass.Works out the engery .
    
    Prints out engery in joules*/
    
    void engery (){     
    
    float e;
    float m;
    
        printf("This works out Mister Einstein most famous equation E=MC squared\nE=Engery\nM=Mass\n C = The speed of light");
        printf(" Please enter in the values for the mass (m)\nPress enter\n" );/*ask user enter in values*/
        scanf("%f",&m);/* get values*/
    
        e=c*c*m;
    
        printf("\nThe Engery is %e joules \n\t",e);/* prints out engery*/
    
    exit();   /*exit fuction running*/
    menu();
    }
     /* Fuction name :lenght
     
    Fuction varibles( All doubles) : l_0 orignal lenght 
    				                l_1 lenght 
    				                v velocity 
    
    Purpose: Ask user to enter in the orignal lenght and velocity.Works out lenght.
    Prints out lenght*/
    void lenght (){     
    float l_0 ;
    float l_1;
    float v;
    
    
    	printf("This works Lenght contraction equation ");
    	printf(" Please enter in the values for \nthe orgnal lenght and the velocity \nPress enter after each value \n");/*ask user enter in values*/
    	scanf("%f%f",&l_0,&v);/* get values*/
    
    	 l_1=l_0*sqrt(1-(v*v)/(c*c));
    
        printf("\nThe lenght is %e meters\n\t",l_1);/* prints out lenght */
    
    exit();
    menu();
    
    }
    /* Fuction name :time
     
    Fuction varibles( All floats) : t_0 time at rest
                                     t time
    								 v velocity
                                    
    				   
    				    
    
    Purpose: Ask user to enter in the time at rest.Works out works time.
    Prints out time*/
    void time (){
    float t ;
    float t_1;
    float v;
    
    
    
    	printf("This works Time dialation equation ");
    	printf(" Please enter in the values for\n the time at rest and the velocity.\nPressenter after each vaule  \n");/*ask user enter in values*/
    	scanf("%f%f",&t_1,&v);/* get values*/
    
    	 t=t_1/sqrt(1-(v*v)/(c*c));
    
    
    
        printf("\n\n\n\n\n\n\nThe time is %e seconds\n\t\n",t);/* prints out time */
    
    exit();
    menu();
    
    }
    
    
    /* Fuction name :momentum
     
    Fuction varibles( All floats) :  m_0 orignal mass
                                     p  momentum
    								 v velocity
                                    
    				   
    				    
    
    Purpose: Ask user to enter in the ogrignal mass and velocity.Works out works momentum.
    Prints out momentum*/
    
    
    
    
    void momentum (){
    float p ;
    float m_0;
    float v;
    
    	printf("This works  equation Relativistic Momentum");
    	printf(" Please enter in the values \nfor the orignal mass and the velocity \nPress enter after each value\n");/*ask user enter in values*/
    	scanf("%f%f",&m_0,&v);/* get values*/
    
    	p=(m_0)*(v)/sqrt(1-(v*v)/(c*c));
    
        printf("\nThe momentum is %e\n\n\n",p);/* prints out momentum*/
    
    exit();
    menu();
    
    }
    /* Fuction name :Kenetic_Eng
     
    Fuction varibles( All floats) :  m_0 ogrignal mas
                                     v velocity
    								 ke kentic_Eng
                                    
    				   
    				    
    
    Purpose: Ask user to entert in the ogrignal mass and velocity.Works out works kentic engery.
    Prints out Kentic engery*/
    
    void Kenetic_Eng (){
    float ke ;
    float m_0;
    float v;
    
    	printf("This works   Kenetic Engery equation");
    	printf(" Please enter in the values for \nthe orignal mass   and the velocity \n Press enter after each value\n");/*ask user enter in values*/
    	scanf("%f%f",&m_0,&v);/* get values*/
    
    	ke=(m_0)*(c)*sqrt(1-(v*v)/(c*c));
    
        printf("\nThe Kenetic Engery is %e\n\n\n",ke);/* prints out KE*/
    
    exit();
    menu();
    }
    
    /* Fuction name :mass
     
    Fuction varibles( floats) :      m_0 ogrignal mas
                                     v velocity
    								 m kentic_Eng
                                    
    				   
    				    
    
    Purpose: Ask user to entert in the ogrignal mass and velocity.Works out works mass.
    Prints out mass*/
    
    void mass (){
    float m;
    float m_0;
    float v;
    
    printf("This works Relarive Mass equation ");
    printf(" Please enter in the values \nfor the orignal mass   and the velocity \nPress enter after each value\n");/*ask user enter in values*/
    scanf("%f%f",&m_0,&v);/* get values*/
    
    m=(m_0)/sqrt(1-(v*v)/(c*c));
    
        printf("\nThe momentum is %e \n\n\n",m);/* prints out mass*/
    
    exit();
    menu();
    }
      /*Ester Egg fuction*/
    void st(){
    
        printf( "\n\nUSS ENTERPRISE NCC-1701-E\n\n\n LAUNCHED IN 2372\n\n\nCO CAPTIAN JEAN -LUC PICARD\n\n\n XO  CRMD.WILLIAM T RIKER\n\n\n 2ND XO LT.CRMD DATA\n\n\n");
    
        exit();                                 /*prints out ester egg.What do you think???????*/
        menu();
        }

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Code:
     /*fuction to exit program*/
    int exit(){
    	 system("PAUSE");
    	 return 0;
          }
    
    ...
        exit();
        menu();
    }
    There are a few problems here:

    1) There is already a function called exit() in stdlib.h, so you shouldn't be making your own.

    2) The exit function does not exit the program. At least, yours doesn't. The real one does. Yours does nothing other than pause for a moment before 'menu' gets called recursively.

    3) You are calling menu() recursively.

    4) If your exit program did work correctly, the menu() call you have would never happen, and as such, would be unreachable code.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    7

    Sorry

    Sorry I forgot i posted it before, it so long since i been on cprogramming.com, and thanks for the the advice.
    Mach_ie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. GUI Calculator - Critique
    By The Brain in forum Windows Programming
    Replies: 1
    Last Post: 02-25-2006, 04:39 AM
  2. Calculator + LinkedList
    By maro009 in forum C++ Programming
    Replies: 20
    Last Post: 05-17-2005, 12:56 PM
  3. Need help with calculator program
    By Kate in forum C# Programming
    Replies: 1
    Last Post: 01-16-2004, 10:48 AM
  4. Einstine calculator Mark 2
    By Mach_ie in forum C Programming
    Replies: 1
    Last Post: 08-31-2003, 01:54 PM
  5. Replies: 2
    Last Post: 05-10-2002, 04:16 PM