Help Me I got this program running but there is some problem

This is a discussion on Help Me I got this program running but there is some problem within the C++ Programming forums, part of the General Programming Boards category; Code: #include<stdio.h> /*Preprocessor Directives*/ #include<math.h> /*Preprocessor Directives*/ void load_menu (void); /*Function declaration of main menu*/ void load_submenu(void); /*Function declaration of ...

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    5

    Help Me I got this program running but there is some problem

    Code:
    #include<stdio.h>							/*Preprocessor Directives*/
    #include<math.h>							/*Preprocessor Directives*/
    
    void load_menu (void);		/*Function declaration of main menu*/	
    void load_submenu(void);	/*Function declaration of Chapter 2 submenu*/
    void load_submenu2(void);	/*Function declaration of Chapter 3 submenu*/
    void asking1(void);		/*Function declaration of pressure*/
    void rest1(void);		/*Function declaration of distance*/	
    void rest2(void);		/*Function declaration of displacement*/
    void rest3(void);		/*Function declaration of speed*/
    void rest4(void);		/*Function declaration of velocity*/
    void rest5(void);		/*Function declaration of acceleration*/
    void scorpions1(void);	/*Function declaration of definition of distance*/
    void scorpions2(void);	/*Function declaration of equation of distance*/
    void scorpions3(void);	/*Function declaration of tutorial of distance*/
    void downy1(void);	/*Function declaration of definition of displacement*/
    void downy2(void);	/*Function declaration of equation of displacement*/
    void downy3(void);	/*Function declaration of tutorial of displacement*/
    void speed1(void);
    void speed2(void);
    void speed3(void);
    void velocity1(void);
    void velocity2(void);
    void velocity3(void);
    void acceleration1(void);
    void acceleration2(void);
    void acceleration3(void);
    void pressure1(void);
    void pressure2(void);
    void pressure3(void);
    
    int main(int argc, char** argv)
    {
    	load_menu();
    	return 0;
    }
    
    void load_menu(void)
    {
    	int choice;
    	
    do{
    	
    printf("			*********************************\n");
    printf("			*	PHYSICS: Chapter 2 and 3	*\n");
    printf("			*	CHAPTER 2 (Linear Motion)	*\n");
    printf("			*	CHAPTER 3 (Pressure)     	*\n");
    printf("			*********************************\n");
    
    printf("\n\t1. Chapter 2\n");
    printf("\t2. Chapter 3\n");
    printf("\t3. Choose 3 to exit this program\n");
    
    	printf("\n\tChoice:");
    	scanf("\n%d", &choice);
    
    switch(choice){
    	
    	case 1: load_submenu();
    		break;
    	case 2: load_submenu2();
    		break;
    	case 3: printf("Exit the program\n");
    		break;
    	default: printf("Invalid Choice!\n");
    		break;
    		}
    		
    	}	while(choice !=3);
    
    }
    
    void load_submenu(void)
    {
    	int choice;
    	
    do{
    	
    	printf("         ***************************\n");
    	printf("         *		   CHAPTER 2	   *\n");
    	printf("		 *		 LINEAR MOTION     *\n");
    	printf("		 ***************************\n");
    	
    	printf("\t1. Distance\n");
    	printf("\t2. Displacement\n");
    	printf("\t3. Speed\n");
    	printf("\t4. Velocity\n");
    	printf("\t5. Acceleration\n");
    	printf("\t6. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		scanf("\n%d", &choice);
    
    	switch(choice){
    		
    		case 1: rest1();
    			break;
    		case 2: rest2();
    			break;
    		case 3: rest3();
    			break;
    		case 4: rest4();
    			break;
    		case 5: rest5();
    			break;
    		case 6: load_menu();
    			break;
    		default: printf("Invalid Choice!\n");
    			break;
    		}
    		
    	} while(choice !=6);
    }
    
    void load_submenu2(void)
    {
    	int choice;
    	
    do
    	{
    	printf("         *****************************\n");
    	printf("		 *			CHAPTER 3		 *\n");
    	printf("		 *			PRESSURE		 *\n");
    	printf("		 *****************************\n");
    
    	printf("\t\t1. Pressure\n");
    	printf("\t2. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    		switch(choice){
    			
    			case 1: asking1();
    					break;
    			case 2: load_menu();
    					break;
    			default: printf("Invalid Choice!\n");
    					break;
    			}
    	} while(choice !=2);
    }
    
    void rest1(void)
    {
    	int choice;
    	
    do
    	{
    	printf("   ********************\n");
    	printf("   *DISTANCE(Chapter 2*\n");
    	printf("   ********************\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 2 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    	switch(choice){
    		
    		case 1: scorpions1();
    			break;
    		case 2: scorpions2();
    			break;
    		case 3: scorpions3();
    			break;
    		case 4: load_submenu();
    			break;
    		case 5: load_menu();
    			break;
    		default: printf("Invalid choice!\n");
    			break;
    		}
    			
    	} while(choice !=5);
    		
    }
    
    void scorpions1(void)
    {
    	int ch;
    	
    	printf("DEFINITION of DISTANCE:\n");
    	printf("-The total length of the path moved by an object.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void scorpions2(void)
    {
    	int ch;
    	
    	printf("EQUATION of DISTANCE: \n");
    	printf("-Distance = Speed X Time\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void scorpions3(void)
    
    {
    	int point1, point2, sum, ch;
    	
    	printf("Calculate distance between point A and point B\n");
    	
    		printf("		Enter speed: ");
    		scanf("%d\n", &point1);
    		printf("		Enter time taken: ");
    		scanf("%d\n", &point2);
    		
    	sum=point1*point2;
    	
    	printf("The distance is %d\n", sum);
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void rest2(void)
    {
    	int choice;
    	
    do
    	{
    	printf("	  ~~~~~~~~~~~~~~\n");
    	printf("	  ~DISPLACEMENT~\n");
    	printf("	  ~~~~~~~~~~~~~~\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 2 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    	
    	switch(choice){
    	
    			case 1: downy1();
    				break;
    			case 2: downy2();
    				break;
    			case 3: downy3();
    				break;
    			case 4: load_submenu();
    				break;
    			case 5: load_menu();
    				break;
    			default: printf("Invalid choice!\n");
    				break;
    		}
    			
    	} while(choice !=5);
    }
    
    void downy1(void)
    
    {
    	int ch;
    
    	printf("DEFINITION of DISPLACEMENT: \n");	
    	printf(" -The shortest distance between the final positions\n");
    	printf("  of an object to a reference point in a specified\n");
    	printf("  direction.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;	
    }
    
    void downy2(void)
    {
    	int ch;
    	
    	printf("EQUATION of DISPLACEMENT: \n");
    	printf("-Displacement = Velocity X Time\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    
    }
    
    void downy3(void)
    {
    	int point1, point2, sum, ch;
    	
    		printf("Enter velocity: \n");
    		scanf("%d", &point1);
    		printf("Enter time taken: \n");
    		scanf("d", &point2);
    		
    	sum=point1*point2;
    	
    	printf("The displacement is %d", sum);
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    	
    }
    
    void rest3(void)
    {
    	int choice;
    	
    do
    	{
    	printf("   ~~~~~~~~~~~~~~~~~~\n");
    	printf("   ~SPEED(Chapter 2)~\n");
    	printf("   ~~~~~~~~~~~~~~~~~~\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 2 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    	switch(choice){
    		
    		case 1: speed1();
    			break;
    		case 2: speed2();
    			break;
    		case 3: speed3();
    			break;
    		case 4: load_submenu();
    			break;
    		case 5: load_menu();
    			break;
    		default: printf("Invalid choice!\n");
    			break;
    		}
    			
    	} while(choice !=5);
    }
    
    void speed1(void)
    {
    	int ch;;
    	
    	printf("DEFINITION of SPEED: \n");
    	printf("- The rate change of distance with time.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    	
    }
    
    void speed2(void)
    {
    	int ch;
    	
    	printf("EQUATION of SPEED: \n");
    	printf("-Speed = Distance(m)/Time(s)\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void speed3(void)
    {
    	int point1, point2, sum, ch;
    	
    	printf("Enter distance(in meter): \n");
    	scanf("%d", &point1);
    	printf("Enter time taken: \n");
    	scanf("%d", &point2);
    	
    	sum=point1/point2;
    	
    		printf("The speed is %d\n");
    		return;
    		
    		while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void rest4(void)
    {
    	int choice;
    	
    do
    	{
    	printf("	  ~~~~~~~~~~\n");
    	printf("	  ~VELOCITY~\n");
    	printf("	  ~~~~~~~~~~\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 2 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    	
    	switch(choice){
    	
    			case 1: velocity1();
    				break;
    			case 2: velocity2();
    				break;
    			case 3: velocity3();
    				break;
    			case 4: load_submenu();
    				break;
    			case 5: load_menu();
    				break;
    			default: printf("Invalid choice!\n");
    				break;
    		}
    			
    	} while(choice !=5);
    }
    	
    void velocity1(void)
    {
    	int ch;
    	
    	printf("DEFINITION of VELOCITY: \n");
    	printf("-The rate of change of displacement with time.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void velocity2(void)
    {
    	int ch;
    
    	printf("EQUATION of VELOCITY: \n");	
    	printf("-Velocity = Displacement(m)/Time(s)\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void velocity3(void)
    {
    	int point1, point2, sum, ch;
    	
    	printf("Enter displacement: \n");
    	scanf("%d", &point1);
    	printf("Enter time taken: \n");
    	scanf("%d", &point2);
    	
    	sum=point1/point2;
    	
    		printf("The velocity is %d", sum);
    		return;
    		
    		while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void rest5(void)
    {
    	int choice;
    	
    do
    	{
    	printf("   ~~~~~~~~~~~~~~\n");
    	printf("   ~ACCELERATION~\n");
    	printf("   ~~~~~~~~~~~~~~\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 2 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    	switch(choice){
    		
    		case 1: acceleration1();
    			break;
    		case 2: acceleration2();
    			break;
    		case 3: acceleration3();
    			break;
    		case 4: load_submenu();
    			break;
    		case 5: load_menu();
    			break;
    		default: printf("Invalid choice!\n");
    			break;
    		}
    			
    	} while(choice !=5);
    }
    
    void acceleration1(void)
    {
    	int ch;
    	
    	printf("DEFINITION of ACCELERATION: \n");
    	printf("-The rate of change of velocity with time.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void acceleration2(void)
    {
    	int ch;
    	
    	printf("EQUATION of ACCELERATION: \n");
    	printf("- Acceleration = (Final velocity-Initial velocity)/Time\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void acceleration3(void)
    {
    	int point1, point2, point3, sum, ch;
    	
    	printf("Enter final velocity: \n");
    	scanf("%d", &point1);
    	printf("Enter initial velocity: \n");
    	scanf("%d", &point2);
    	printf("Enter time taken: \n");
    	scanf("%d", &point3);
    	
    	sum=(point1-point2)/point3;
    	
    		printf("The acceleration is %d\n");
    		return;
    		
    		while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void asking1(void)
    {
    	int choice;
    	
    do
    	{
    	printf("   ~~~~~~~~~~~~~~~~~~~~~\n");
    	printf("   ~PRESSURE(CHAPTER 3)~\n");
    	printf("   ~~~~~~~~~~~~~~~~~~~~~\n");
    	printf("\n\t1. Definition\n");
    	printf("\t2. Equation\n");
    	printf("\t3. Tutorial\n");
    	printf("\t4. Back to Chapter 3 menu\n");
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    	switch(choice){
    		
    		case 1: pressure1();
    			break;
    		case 2: pressure2();
    			break;
    		case 3: pressure3();
    			break;
    		case 4: load_submenu2();
    			break;
    		case 5: load_menu();
    			break;
    		default: printf("Invalid choice!\n");
    			break;
    		}
    			
    	} while(choice !=5);
    }
    
    void pressure1(void)
    {
    	int ch;
    	
    	printf("DEFINITION of PRESSURE: \n"); 
    	printf("-The force acting per unit area.\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void pressure2(void)
    {
    	int ch;;
    	
    	printf("EQUATION of PRESSURE: \n");
    	printf("-Pressure = Force/Area\n");
    	return;
    	
    	while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }
    
    void pressure3(void)
    {
    	int point1, point2, sum, ch;
    	
    	printf("Enter force value: \n");
    	scanf("%d", &point1);
    	printf("Enter area value: \n");
    	scanf("%d", &point2);
    	
    	sum=point1/point2;
    	
    		printf("The pressure is %d", sum);
    		return;
    		
    		while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    }

  2. #2
    Registered User
    Join Date
    Oct 2006
    Posts
    2,361
    ok, so what's the problem?

  3. #3
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Problem is.... ???
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  4. #4
    Registered User
    Join Date
    Mar 2011
    Posts
    5
    the problem is...it won't stop running

  5. #5
    Programming King Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Middle of NoWhere
    Posts
    320
    Code:
    while(choice !=3);
    instead try it.
    Code:
    while(choice>3);
    I don't care if someone doesn't like me, i was not put on earth to entertain everyone.

    No King, no Queen, I am the ACE of battle.

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,494
    Code:
    	printf("\t5. Main Menu\n");
    	
    		printf("\n\tChoice:");
    		printf("\n%d", &choice);
    		
    	switch(choice)
    What value do you think choice now has?
    Perhaps you meant scanf, what with the &choice and all.

    If you use GCC as your compiler, it would have told you that.


    Then this (in MANY places)
    Code:
    	sum=point1/point2;
    	
    		printf("The pressure is %d", sum);
    		return;
    		
    		while ((ch = getchar()) != '\n' && ch != EOF) ;
    
    	printf("\n\nPress ENTER to continue.");
    	while ((ch = getchar()) != '\n' && ch != EOF)
    		;
    
    	return;
    
    ALL the code in red never gets a chance to execute, because the function is over at the first return statement.
    You do this in lots of places.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with a Battleship Program
    By HBlakeH in forum C Programming
    Replies: 1
    Last Post: 12-05-2010, 10:13 PM
  2. Problem running program
    By JOCAAN in forum C++ Programming
    Replies: 3
    Last Post: 10-19-2007, 04:09 PM
  3. How to tell when internal program is done running
    By PJYelton in forum Windows Programming
    Replies: 5
    Last Post: 03-21-2005, 09:09 PM
  4. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  5. Problem running program in Win98
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 10-19-2003, 12:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21