Thread: getting an error ???

  1. #91
    Registered User
    Join Date
    Aug 2007
    Posts
    59
    Quote Originally Posted by QuantumPete View Post
    "The C Programming Language" by Kernighan and Ritchie (Second Edition) page 153/154

    QuantumPete

    Heh , a bit too late for that now , the assignement is due tomorrow

  2. #92
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Quote Originally Posted by ki113r View Post
    Heh , a bit too late for that now , the assignement is due tomorrow
    I'm sure there's a Barnes & Noble or Waterstones near you, plus your departmental library should have a copy.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  3. #93
    Registered User
    Join Date
    Aug 2007
    Posts
    59
    Does that book say something like this :
    printf("The aperture value entered is : %.1ff");
    But I get :
    The aperture value entered is : 0.0f .
    Any idea on what I'm doing wrong ?

  4. #94
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    yeah, well you're trying to print out the aperture value, but do you see aperture in your printf???

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

  5. #95
    Registered User
    Join Date
    Aug 2007
    Posts
    59
    Quote Originally Posted by QuantumPete View Post
    yeah, well you're trying to print out the aperture value, but do you see aperture in your printf???

    QuantumPete
    oh how embarrassing .... / goes to hide under a rock

  6. #96
    Registered User
    Join Date
    Aug 2007
    Posts
    59

    Finally finished everything

    Ok before I hand this in , can someone just please go over my indenting , because I haven't done it before . I assume there isno strict rules , just making the code easier to read. Did I indent the code ok ? Thanks again

    Code:
    #include <stdio.h>
    int main(void)
    
    {
    
    	int exposure=0;		//Initiate the exposure variable - integer 
    	float aperture=0;	//Initiate the aperture variable - floating point number
    	int choice = 0;		//Initiate the choice variable - used in the while loop 
    
    	printf("\nEnter Exposure Time: ");	// Prompt the user for exposure time
    	scanf("&#37;d",&exposure);			// Store exposure time in the exposure variable
    
    	printf("The selected Exposure time is %d\n", exposure);		        // Print the exposure time entered on screen
    
    
    	// Initiate the while loop
    
    
    	{
    
    
    			while (choice<1)
    		{
    				printf ("Please enter the aperture size - *like so : x.yf*\n");	// Prompt the user for the aperture size.
    				scanf("%ff",&aperture);					        // Store the aperture value in the aperture variable. 
    		
    				if
    		  		   (
    					   (aperture==1.2f)  || (aperture==1.4f) 
                      			|| (aperture==2.0f)  || (aperture==2.8f)
                      			|| (aperture==2.8f)  || (aperture==4.0f)      // Check to see if the value entered corresponds to one of the values 	                                     || (aperture==5.6f)  || (aperture==8.0f)      // that are allowed.
                      			|| (aperture==11.0f) || (aperture==16.0f)
                      			|| (aperture==22.0f) || (aperture==32.0f)
    					|| (aperture==1.8f) 	
    				   )	
    			{
    
    					printf("You have entered a defined aperture. \nThe aperture value entered is  : %.1ff\n",aperture);
    	
    					choice=2; // Set the choice variable to 2 to provide a condition for exit of the loop. 
    			}
    	
    					
    			                else
    
    	
    			{
    					printf("You have entered aperture value of %.1ff. \n This is an invalid aperture, please try Again\n", aperture);							     // Alert the user that incorrect value was entered.
    			
    					choice=0; // Set the choice variable to 0 so that condition is still true - and the program will loop.
    			}	
    
    
    
    		}
    
    
    	}
    
    
    }
    Last edited by ki113r; 09-06-2007 at 04:41 PM.

  7. #97
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Apertures are "f5.6" not "5.6f" (I think the absolutely correct way to write apertures is f/5.6, because that is exactly what the aperture represents, the focal-length divided by 5.6 is the size of the opening of the lens). Obviously the number 5.6 could be any of the numbers listed (and others). So you need to use "f%f" in your scanf call. Remeber to change the explanatory text too!

    You have an extra set of braces around your while-loop. They serve absolutely no purpuse.

    The while is indented further than the brace corresponding to the while - I prefer to have them equal or braces further in.

    You have 2.8 twice in the list of valid f-values. You are missing 5.6 and 8 on the other hand. It would be good to have 1.8 close to the front, rather than at the back end (otherwise you look at it quickly and think it's missing).

    Why can't "choice" (which should probably be called "valid") be 0 and 1 only - there's no reason for it to be 0 and 2. Just set it to 0 and use while(!valid). Set to 1 when correct value has been entered, don't change it if an incorrect value has been entered.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  8. #98
    Registered User
    Join Date
    Aug 2007
    Posts
    59

    Unhappy

    /Edit That aperture==f4.0 is in fact in line with the rest of the values in my code .

    I changed some thins now .However I get quite a few errors .
    Code:
    {
    ^
    test5(27) : Error: '(' expected following if
                                               (aperture==f1.2)
                                                             ^
    test5(29) : Error: undefined identifier 'f1'
                                            || (aperture==f1.4)
                                                             ^
    test5(30) : Error: ')' expected
                                            || (aperture==f1.8)
                                             ^
    test5(31) : Error: '=', ';' or ',' expected
                                    else
                                       ^
    test5(52) : Error: '=', ';' or ',' expected
    Fatal error: too many errors
    --- errorlevel 1
    Here is my code :

    Code:
    #include <stdio.h>
    int main(int argc, char * argv[])
    
    {
    
    
    // Mainline Variable Declarations
    FILE * output = stdout;
    FILE * input = stdin;
    
    
    
    	int exposure=0;		//Initiate the exposure variable - integer 
    	float aperture=0;	//Initiate the aperture variable - floating point number
    
    
    	fprintf(output,"\nEnter Exposure Time: ");	// Prompt the user for exposure time
    	fscanf(input,"&#37;d",&exposure);			// Store exposure time in the exposure variable
    
    	
    
                               
    				fprintf(output,"Please enter the aperture size - *like so : fx.y*\n");	// Prompt the user for the aperture size.
    				fscanf(input,"f%f",&aperture);					        // Store the aperture value in the aperture variable. 
    		
    			if
    {
    		  		   (
    					   (aperture==f1.2) 
                                            || (aperture==f1.4) 
                                            || (aperture==f1.8) 
                      			|| (aperture==f2.0)  
                                            || (aperture==f2.8)                                                                                                                                          || (aperture==f4.0)      // Check to see if the value entered corresponds to one of the values 	                                                          || (aperture==f5.0) 
                                            || (aperture==f8.0)      // that are allowed.
                      			|| (aperture==f11.0) 
                                            || (aperture==f16.0)
                      			|| (aperture==f22.0) 
                                            || (aperture==f32.0)
    						
    				   )
    	
    			{
    
    					fprintf(output,"You have entered a defined aperture.\n")
    					fprintf(output,"::::::Values::::::Entered::::::\n\n")
    					
    					fprintf(output,"The selected Exposure time is %d\n", exposure);         // Print the exposure time entered on screen
    					fprintf(output,"The selected Aperture is  : f%.1f\n",aperture);		// Print the aperture on screen
    		
    
    			}	
    
    		
    				else
    			
    
    
    			{
    					fprintf(output,"You have entered aperture value of f%.1f. \n", aperture)
    					fprintf(output,"This is an invalid aperture, the program will now exit\n") 								                     // Alert the user that incorrect value was entered.
    			                break;
    					
    		        }
    
    
    }
    I really can't see any problems with that code. Help please
    Last edited by ki113r; 09-06-2007 at 05:50 PM.

  9. #99
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    f1.2 isn't a float, etc. etc..

  10. #100
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    you put the f after the number for a float value.

    float = 3.4f;
    not
    float = f3.4;

  11. #101
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    ki113r you seem to ignore 99&#37; of what people say and go off and do your own thing, hence the size of this thread. Consider taking a minute to read what other people have to say...

  12. #102
    Registered User
    Join Date
    Aug 2007
    Posts
    59
    Quote Originally Posted by zacs7 View Post
    ki113r you seem to ignore 99% of what people say and go off and do your own thing, hence the size of this thread. Consider taking a minute to read what other people have to say...
    The size of this thread is mostly due the fact that some of the comments don't really help me much , very much like your post . If you actually read through you would see that the f in front stands for the aperture value , NOT a float . It used to be 1.2f , which is incorrect just like matsp pointed out , and he was right when he said that the f goes in the beginning . If you don't want to help then thats fine but there's no need to post such comments. I very much doubt that you followed this thread from the beginning , which limits how much you are entitled on your opinion. What does size of this thread have to do with it ? Your thinking is wrong .

  13. #103
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    f goes in the beginning only in strings. That's the syntax for f-stops in the field of photography.
    Code:
    printf("my camera is set to f1.0");
    f goes at the end for floats. that's the syntax for C and C++.
    Code:
    float float_val = 1.0f;
    printf("my camera is set to f&#37;f",float_val);
    
    /*or with a constant*/
    printf("my camera is set to f%f",1.0f);
    Last edited by robwhit; 09-07-2007 at 11:46 AM.

  14. #104
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, I suppose I should have pointed out the difference between the f in C and the f in photography. It's just pure coincidence that they are very similar - well, the fact that the words "Focal Length" and "float" both start with the letter F is what makes them similar.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM