Thread: Enistine program

  1. #1
    Mac_the vamp
    Guest

    Talking Enistine program

    Hi jsut finished my Einstine program tell what you think here the source code.

    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();
    #define c 3E8
    
    void main()
    {    void menu (); /* function prototype*/
         printf("\n\tWelcome to Machsofts Einstine calculator.\n\tThis program will \n\tcalculate all of the equatios for Einstines 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*/
    
    }
    
    void 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;
     }
    
    }
    
     /*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 Eniestine most famous equation E=MC squared\nE=Engery\nM=Mass\n C = The speed og 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 Enger is %G 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_1);/* prints out lenght */
    
    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();
        }
    Oh there is also a little surpries for trekkies

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    I don't have a compiler at this moment to test your program, so I will only take a look at your code.

    The code looks fine (found one bug and some strange things):

    1. Place function prototypes outside of main (void menu())
    2. void main is wrong, use int main and return something at the end of main
    3. Exit is a reserved word. It's best to rename your function
    4. A function automatically returns to the caller function after it's finished. Don't call menu() (only in main) BUG
    5. Make a while loop in main

  3. #3
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    learn to spell "einstein"
    hello, internet!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Issue with program that's calling a function and has a loop
    By tigerfansince84 in forum C++ Programming
    Replies: 9
    Last Post: 11-12-2008, 01:38 PM
  2. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 01:41 PM
  3. Replies: 4
    Last Post: 02-21-2008, 10:39 AM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM