![]() |
| BMI Calculator |
BMI (Body Mass Index) Calculator
Drag Labels and Sliders
i ) Insert headings for some Labels and for other Labels map the Sliders.
ii) There is no need to change Main.m, AppDelgate.h, AppDelegate.m ..
ViewController.h
#import <UIKit/UIKit.h>
@interface venViewController : UIViewController{
IBOutlet UISlider *heightValue;
IBOutlet UISlider *weightValue;
IBOutlet UILabel *height;
IBOutlet UILabel *weight;
IBOutlet UILabel *bmiVal;
IBOutlet UILabel *result;
}
-(IBAction)heightSlider:(id)sender;
-(IBAction)weightSlider:(id)sender;
-(NSString *)range:(float)bmiVal;
@end
ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)heightSlider:(id)sender{
float hval=(float)heightValue.value;
NSString *lbl=[NSString stringWithFormat:@"%f",hval];
height.text=lbl;
}
-(IBAction)weightSlider:(id)sender{
float wval=(float)weightValue.value;
NSString *label=[NSString stringWithFormat:@"%f",wval];
weight.text=label;
float h=[height.text floatValue];
float w=[weight.text floatValue];
float Val =w/((h/100)*(h/100));
NSString *bmiResult=[NSString stringWithFormat:@"%lf",Val];
bmiVal.text=bmiResult;
[self range:Val];
}
-(NSString *)range:(float)bmiVal2{
if (bmiVal2<16.5) {
result.text=@"severly underweight";
}
else if (bmiVal2<18.5) {
result.text=@"underweight";
}
else if (bmiVal2<25) {
result.text=@"normal";
}
else if (bmiVal2<35) {
result.text=@"severely obessed";
}
return result.text;
}
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(IBAction)heightSlider:(id)sender{
float hval=(float)heightValue.value;
NSString *lbl=[NSString stringWithFormat:@"%f",hval];
height.text=lbl;
}
-(IBAction)weightSlider:(id)sender{
float wval=(float)weightValue.value;
NSString *label=[NSString stringWithFormat:@"%f",wval];
weight.text=label;
float h=[height.text floatValue];
float w=[weight.text floatValue];
float Val =w/((h/100)*(h/100));
NSString *bmiResult=[NSString stringWithFormat:@"%lf",Val];
bmiVal.text=bmiResult;
[self range:Val];
}
-(NSString *)range:(float)bmiVal2{
if (bmiVal2<16.5) {
result.text=@"severly underweight";
}
else if (bmiVal2<18.5) {
result.text=@"underweight";
}
else if (bmiVal2<25) {
result.text=@"normal";
}
else if (bmiVal2<35) {
result.text=@"severely obessed";
}
return result.text;
}
@end
tags:bmi calculator code for iphone app,code for bmi calculator,code for bmi calculator in ios, iphone sample projects, sample programs in iphone, sample apps for iphone with source code

Posted in:
0 comments:
Post a Comment