Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
C - a first program that does something useful for you

Any language has a whole number of different types of element that come together to make a whole.

Let's take a spoken language such as English. You need nouns - they're 'thing' words like "platypus" and "road", "carrot" and "Walter". Then you need verbs to join them together - they're 'doing' words like "ate" and "squash", "is" and "craved". Using those basics you can achieve, but in a very limited and stilted way, some real meaning - "Walter ate carrot", but you need more to get the full depth of expression that we use in day to day life - add in your prepositions, adverbs and adjectives, and also add different structure in which you can use, qualify and modify the elements you've already got. For example "Some carrots were squashed on the road" is using the same nouns and verbs, but within other structures and you'll notice that "carrot" has been plurasised into "carrots", and "squash" moved back into the past in the form of "squashed".

There's a similar thing with programming languages - you need more that just one basic element to get you started with something meaningful, and even when you get to that first meaningful program, you'll be very limited in what you can do. That's just an early limit, though - as you learn about more language elements, and as you also learn how to adopt / adapt / tailor the basic elements you learned early on, you end up finding that the sky's the limit.

Programming courses always start with a program that outputs a message such as "Hello World". Just as a French teacher might start "Bonjour" and an Arabic teacher would start "Al salaam a'alaykum" - litereally meaning "peace be with you". The second step is to do something useful - convey a message, write a piece of code which reads an input from the user of your program, does some sort of calculation, and outputs the result.

On our programming courses, we take this "one, two" step as well ... and on the C Programming course I ran at the beginning of last week, I wrote a program that asked the user to enter his weight and height, calculated his Body Mass Index (BMI) and output the result. I'm told that if this number is under 20, it indicates "underweight" and over 25, you're getting a bit chubby. ((I'm also reminded to tell you I'm NOT a doctor and you should seek medical advise if anything concerns you, whatever your BMI is!))

Anyway - the program ... highlights ... features used / added beyond "Hello World":

Setting up a named memory location (a variable):
  float height;

Reading a value into a variable:
  scanf("%f",&height);

Doing a calculation and saving the answer into another variable:
  bmi = weight / (height * height);

Outputting the contents of a variable (in amongst descriptive text):
  printf ("And my BMI is %.2f\n",bmi);

The full program is [here]. And here's an example of it running:

  munchkin:capr grahamellis$ ./second
  How high are you (metres): 1.75
  How hefty are you (kilograms): 66
  I am here
  My height is 1.75 and I weigh 66.0
  And my BMI is 21.55
  munchkin:capr grahamellis$


Very clunky ... a bit long winded ... no error checking for inputs that are obviously wrong ... no conditional checks which would allow me to add an extra warning for my users if the BMI was a bit high. But a first practical program!

If you would like to learn more about our C and C++ courses, see [here]. There are five different courses, ranging from 2 to 5 days in length - choose the course that's right for YOU based on your background and whether you need to learn only the C language, or C++.
(written 2011-04-09)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
C202 - C and C based languages - A first practical program
  [888] Turning C from source to a running program - (2006-10-06)
  [2580] C course inspires new teaching examples - (2010-01-16)
  [3121] New year, new C Course - (2011-01-05)
  [3590] Defining, declaring and initialising variables in C - (2012-01-24)
  [4337] Learning to program sample program - past its prime, but still useful - (2014-12-02)
  [4632] Remember to ask the question before you listen for the answer - (2016-01-26)


Back to
How we make our programming courses both time and cost effective
Previous and next
or
Horse's mouth home
Forward to
Using functions to keep look and feel apart from calculations - simple C example
Some other Articles
Melksham Town Council - vacancy in the Spa Ward
TrainWest, 2011 in pictures - Christie Miller, Bowerhill, Melksham
Bradshaw, Ben and Bill. And some C and C++ pointers and references too.
Using functions to keep look and feel apart from calculations - simple C example
C - a first program that does something useful for you
How we make our programming courses both time and cost effective
Your program - you just provide the filling in the sandwich
C / C++ Course Lunch - sitting out at the West End
Around and about Melksham in more pictures
Footpath, Bridleway, Byway, Road used as Public Path
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/3236_C-a ... r-you.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb