• Portfolio
  • Archive
    • Grad Students Halloween Party 2016
    • Praxis Showcase 2010 Highlights
    • 2015 Canada Blooms Near North Hardscapes
    • 2014 IEEE Toronto AGM Highlights
    • 2014 GSU Halloween Party
    • 2014 GSU Halloween Party 2
    • IEEE Day: Wine and Cheese
    • 2014 Akido Club Photoshoot
    • Canonball 1T5
    • 2014 Toronto Christmas Market
    • 2015 Nocturne
    • Cute-Baby-TBP
  • Stuff.
  • Contact Info

kmingk

Just Me.

  • Portfolio
  • Archive
    • Grad Students Halloween Party 2016
    • Praxis Showcase 2010 Highlights
    • 2015 Canada Blooms Near North Hardscapes
    • 2014 IEEE Toronto AGM Highlights
    • 2014 GSU Halloween Party
    • 2014 GSU Halloween Party 2
    • IEEE Day: Wine and Cheese
    • 2014 Akido Club Photoshoot
    • Canonball 1T5
    • 2014 Toronto Christmas Market
    • 2015 Nocturne
    • Cute-Baby-TBP
  • Stuff.
  • Contact Info

APS105 Tutorial 1

The code is meant to take a program description (in comments) and convert that to code. Mainly uses boundary checks and conditions and input/output

  • If statement order matters --> Try for yourself and change the ordering of the if statement
  • The & in front of the variable means that we are passing an address. This is needed for scanf.
/* 
 * File: main.c
 * Author: user
 *
 * Created on September 21, 2015, 9:11 AM
 */

#include <stdio.h>
#include <stdlib.h>

/*
 * Build a program that computes a person's Body Mass Index. BMI is computed as 
 * BMI = Person's Weight (KG)/ Person's Height (m) ^2 and tell if a person is
 * overweight.Overweight BMI is 25.
 * 
 */

int main(int argc, char** argv) {
// Get user's height and weight
double height, weight, BMI;
printf("Please enter the height(m): ");
scanf("%lf", &height);
printf("Please enter the weight(kg): ");
scanf("%lf", &weight);

// Compute the BMI: BMI = w/h^2
BMI = weight / (height * height);

// Output BMI
printf("Your BMI \tis: %20.4lf\n", BMI);

// Tell if the user is overweight or not
if (BMI >= 40) {
printf("See a doctor?\n");
} else if (BMI >= 25) {
printf("Overweight\n");
} else {
printf("Normal\n");
}

return (EXIT_SUCCESS);
}
Monday 10.05.15
Posted by Kei-Ming Kwong
Newer / Older