Wednesday, January 22, 2014

Bilogical

------------------------------------------------- Introducing scanf to designate selective information into variables from the keyboard The program be looked at in the previous session was fine to use when working(a) at bottom the C++ IDE (Integrated Development Environment). exactly what if we treasured to give the program to somebody else with unwrap the C compiler, so that they could transpose the years set in the program without having to change the superior source canon? You need some way of let the person (or substance abuser) scotch selective information into the program - the transparent choice being the keyboard. The scanf officiate will wait for the user to case in information at the keyboard, and when they press the enroll key, will take the data they have typed, and place it into a variable. For example, if we valued to read somebodys eld, and compile out the approximate flesh of long time and weeks they have lived, these lead lines of enroll wou ld do the trick (note that this isnt a complete program, so will not work on its own if you type it in): - float maturate,old age,weeks; printf( ship age in years: ); scanf(%f,&age); days = age*365.25; weeks = age*52.0; printf( You have lived for %5f days and %4f weeks, days, weeks ); This assumes the average human activity of days in the year is 365.25 and in that respect are 52 weeks  in the year. The scanf function is a melodic composition like the opposite of the printf function - printf writes  data out to the console, scanf reads data in from the console. Notice that scanf also uses the %f code to represent that we want to read data into a  floating-point variable. If we wanted to read into an integer variable, we would use %d instead. The &age shows that the %f that is read in from the keyboard will be frame in into the age  variable. Why do we need the & in drive of the variable? We will cover this in a  posterior session, w hen we deal with passing variables to functi! ons by reference. Dont  worry more or less this for the moment. But be VERY...If you want to get a spacious essay, mold it on our website: BestEssayCheap.com

If you want to get a full essay, visit our page: cheap essay

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.