#include <stdio.h> #include "stdafx.h" int within_x_percent(double ref,double data,double x) ; double ref; double data; double x = .05; int _tmain(int argc, _TCHAR* argv[]) { printf("Enter the boiling point of the substance: "); scanf("%1f", &data); if (data = within_x_percent(100,data,x)) printf("Your substance is Water.\n"); else if (data = within_x_percent(357,data,x)) printf("Your substance is Mercury. \n"); else if (data = within_x_percent(1187,data,x)) printf("Your substance is Copper. \n"); else if (data = within_x_percent(2193,data,x)) printf("Your substance is Silver. \n"); else if (data = within_x_percent(2660,data,x)) printf("Your substance is Gold. \n"); else printf("Substance Unknown\n"); return 0; } int within_x_percent(double ref,double data,double x) { if (( ref - x * ref) <= data <= (ref + x * ref)) return 1; else return 0; } |
if (data == within_x_percent(100,data,x))
|
|
if (( ref - x * ref) <= data <= (ref + x * ref))
is wrong too, it should be if (( ref - x * ref) <= data || data <= (ref + x * ref))
if (data >=( ref - x * ref) && data <= (ref + x * ref)) |
if ( within_x_percent(100,data,x) )
if (within_x_percent(100,data,x))
|
|