"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
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 ?
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
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("%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.
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.
/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 .
Here is my code :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
I really can't see any problems with that code. Help pleaseCode:#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,"%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; } }
Last edited by ki113r; 09-06-2007 at 05:50 PM.
you put the f after the number for a float value.
float = 3.4f;
not
float = f3.4;
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 .
f goes in the beginning only in strings. That's the syntax for f-stops in the field of photography.f goes at the end for floats. that's the syntax for C and C++.Code:printf("my camera is set to f1.0");Code:float float_val = 1.0f; printf("my camera is set to f%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.
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.