Thread: how to convert double to array

  1. #1
    Registered User
    Join Date
    Nov 2008
    Posts
    6

    how to convert double to array

    i am making a program in which it asks the user to calculate depth of the pit. later on the last estimated value needs to be saved into the file.

    user selects from the following options:
    insert
    Code:
            printf("\t\t\tMain Menu\n\n");
            printf("(D)epth: Enter pit location, Compute depth	  \n");
            printf("(S)ave : Write pits data to file 	\n");
            printf("(L)oad : Read mine shaft information from file.\n");
            printf("(P)rint: Display mine shaft information.\n");
            printf("(Q)uit : Exit program.\n");
    	    printf("Enter choice(D/S/L/P/Q)\n\n");
            scanf("%c",&choice);
            fflush(stdin);
            switch (choice)
    		{
    i have solved the first part
    insert
    Code:
    	case 'd': case 'D':
    		    
    		    	do
    				
    				 { for (i=0; i<1; i++)
                   	    {  printf("Enter the mine shaft location or name:\n");
                   	       fgets(location, 100, stdin);
                        }
    				   printf("\nEnter time in seconds to bottom: \n");
    	               scanf("%lf", &toBottom);
    				   fflush(stdin);
    	               printf("\nShaft depth is %.2f m\n", depth(toBottom)	);
    				}  while( yesNo("Do you want to take another measure"));
    now the last estimated depth needs to get stored in the file for that i need to create array for depth. how should i get the dta into the array?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Stop using fflush(stdin), see the FAQ for why.

    Also, if you use fgets() at all, you should really use it for everything. This generally makes the problem of "needing to flush input" go away.

    So for example,
    scanf("&#37;lf", &toBottom);

    would be (without error checks)
    char buff[BUFSIZ];
    fgets( buff, sizeof buff, stdin );
    sscanf(buff, "%lf", &toBottom);
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  2. Unknown Math Issues.
    By Sir Andus in forum C++ Programming
    Replies: 1
    Last Post: 03-06-2006, 06:54 PM
  3. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM
  4. Replies: 8
    Last Post: 03-10-2005, 08:14 AM
  5. convert double to string problem
    By gandalf_bar in forum C++ Programming
    Replies: 6
    Last Post: 03-15-2004, 05:14 AM