Hello to all. I am a very new xcode, objective-c programmer. I have done some limited programming in other languages. I have written my first, what I will call, successful program in xcode. By this, as the thread title suggest, I mean that there are no errors generated when I run the debugger.
First I will explain what I am trying to accomplish and then I will explain what the issue is.
The program goal:
Just to create a simple math processing program, I decided to write a cooking measurement conversion app. The first set of instructions-converting teaspoon into any of the other measurements goes fine. (first if statement) This works as it should
The issue:
After adding the second set of conversions-from tablespoon to the other measurements (second if statement) When I put a value in, it only calculates one conversion and then places a zero in the rest including the original value that I want to convert. If I do a block comment on either if statement it works correctly. I do not have the knowledge yet to see where my issue is.
Below is the code and sorry for being so long winded.
CMCcontroller.h file below
CMCcontroller.m file
First I will explain what I am trying to accomplish and then I will explain what the issue is.
The program goal:
Just to create a simple math processing program, I decided to write a cooking measurement conversion app. The first set of instructions-converting teaspoon into any of the other measurements goes fine. (first if statement) This works as it should
The issue:
After adding the second set of conversions-from tablespoon to the other measurements (second if statement) When I put a value in, it only calculates one conversion and then places a zero in the rest including the original value that I want to convert. If I do a block comment on either if statement it works correctly. I do not have the knowledge yet to see where my issue is.
Below is the code and sorry for being so long winded.
CMCcontroller.h file below
Code:
#import <Cocoa/Cocoa.h>
float tsptxt;
float tbstxt;
float qtstxt;
float pntstxt;
float oztxt;
float mltrtxt;
float ltrtxt;
float galtxt;
float cuptxt;
@interface CMCcontroller : NSObject {
IBOutlet id cup;
IBOutlet id gal;
IBOutlet id ltr;
IBOutlet id mltr;
IBOutlet id oz;
IBOutlet id pnts;
IBOutlet id qts;
IBOutlet id tbs;
IBOutlet id tsp;
}
- (IBAction)calc:(id)sender;
@end
CMCcontroller.m file
Code:
#import "CMCcontroller.h"
@implementation CMCcontroller
- (IBAction)calc:(id)sender
{
float tsptemp = [tsp floatValue];
float tbstemp = [tbs floatValue];
if (tsp > 0)
{
//THIS IS TO CONVERT TEASPOON TO TABLESPOON
float tsp_tbsresult;
tsp_tbsresult = tsptemp / 3 ;
tbstxt = tsp_tbsresult;
[tbs setFloatValue:tbstxt];
tsptemp = [tsp floatValue];
//THIS IS TO CONVERT TEASPOON TO fl. oz.
float tsp_ozresult;
tsp_ozresult = tsptemp / 6;
oztxt = tsp_ozresult;
[oz setFloatValue: oztxt];
//THIS IS TO CONVERT TEASPOON TO CUPS
float tsp_cupresult;
tsp_cupresult = tsptemp / 48;
cuptxt = tsp_cupresult;
[cup setFloatValue: cuptxt];
//THIS IS TO CONVERT TEASPOON TO PINTS
float tsp_pintresult;
tsp_pintresult = tsptemp / 96;
pntstxt = tsp_pintresult;
[pnts setFloatValue: pntstxt];
//THIS IS TO CONVERT TEASPOON TO QUART
float tsp_qtsresult;
tsp_qtsresult = tsptemp / 192;
qtstxt = tsp_qtsresult;
[qts setFloatValue: qtstxt];
//THIS IS TO CONVERT TEASPOON TO GALLON
float tsp_galresult;
tsp_galresult = tsptemp / 768;
galtxt = tsp_galresult;
[gal setFloatValue: galtxt];
//THIS IS TO CONVERT TEASPOON TO MILLILITER
float tsp_mltrresult;
tsp_mltrresult = tsptemp / .202884136;
mltrtxt = tsp_mltrresult;
[mltr setFloatValue: mltrtxt];
//THIS IS TO CONVERT TEASPOON TO LITER
float tsp_ltrresult;
tsp_ltrresult = tsptemp / 202.884136;
ltrtxt = tsp_ltrresult;
[ltr setFloatValue: ltrtxt];
}
if (tbs > 0)
{
//THIS IS TO CONVERT TABLESPOON TO TEASPOON
float tbs_tspresult;
tbs_tspresult = tbstemp * 3;
tsptxt = tbs_tspresult;
[tsp setFloatValue: tsptxt];
//THIS IS TO CONVERT TABLESPOON TO fl. oz
float tbs_flozresult;
tbs_flozresult = tbstemp / 2;
oztxt = tbs_flozresult;
[oz setFloatValue:oztxt];
//THIS IS TO CONVERT TABLESPOON TO CUP
float tbs_cupresult;
tbs_cupresult = tbstemp / 16;
cuptxt = tbs_cupresult;
[cup setFloatValue:cuptxt];
//THIS IS TO CONVERT TABLESPOON TO PINT
float tbs_pntresult;
tbs_pntresult = tbstemp / 32;
pntstxt = tbs_pntresult;
[pnts setFloatValue:pntstxt];
//THIS IS TO CONVERT TABLESPOON TO QUART
float tbs_qtsresult;
tbs_qtsresult = tbstemp / 64;
qtstxt = tbs_qtsresult;
[qts setFloatValue:qtstxt];
//THIS IS TO CONVERT TABLESPOON TO GALLON
float tbs_galresult;
tbs_galresult = tbstemp / 256;
galtxt = tbs_galresult;
[gal setFloatValue:galtxt];
//THIS IS TO CONVERT TABLESPOON TO MILLILITER
float tbs_mltrresult;
tbs_mltrresult = tbstemp / 0.0676280454;
mltrtxt = tbs_mltrresult;
[mltr setFloatValue:mltrtxt];
//THIS IS TO CONVERT TABLESPOON TO LITER
float tbs_ltrresult;
tbs_ltrresult = tbstemp / 67.6280454;
ltrtxt = tbs_ltrresult;
[ltr setFloatValue:ltrtxt];
}
}
@end