/*********************************************************** ratios.ch Ratios This program is designed to solve for an unknown in the equation: a/b = c/d, where x can be in any location in the two fractions. ************************************************************ Copyright 2014 SoftIntegration Inc. http://www.softintegration.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 ***********************************************************/ //#include //for strtod() printf("Solves ratios: we solve for x in the equation a/b = c/d,\nwhere x can be in any location in the two fractions.\n"); //initialize variables double a,b,c,d, cross; char astr[20], bstr[20], cstr[20], dstr[20]; //Get the values printf("a/b = c/d enter x for the unknown value\n"); printf("what is a? "); scanf("%s", astr); printf("\nwhat is b? "); scanf("%s", bstr); printf("\nwhat is c? "); scanf("%s", cstr); printf("\nwhat is d? "); scanf("%s", dstr); //print the values printf("\n%s",astr); printf("\n%s",bstr); printf("\n%s",cstr); printf("\n%s",dstr); //determine which variable is unknown, calculate and display answer if (astr[0] == 'x') //case a is unknown { b = strtod(bstr, NULL); c = strtod(cstr, NULL); d = strtod(dstr, NULL); cross = c/d; a = cross*b; printf("\na = %lf", a); } else if (bstr[0] == 'x') //case b is unknown { a = strtod(astr, NULL); c = strtod(cstr, NULL); d = strtod(dstr, NULL); cross = c/d; b = a/cross; printf("\nb = %lf", b); } else if (cstr[0] == 'x') //case c is unknown { a = strtod(astr, NULL); b = strtod(bstr, NULL); d = strtod(dstr, NULL); cross = a/b; c = cross*d; printf("\nc = %lf", c); } else if (dstr[0] == 'x') //case d is unknown { a = strtod(astr, NULL); b = strtod(bstr, NULL); c = strtod(cstr, NULL); cross = a/b; d = c/cross; printf("\nd = %lf", d); }