/*********************************************************** foil.ch FOIL This program FOILs an expression of the form: (ax + b)(cx + d) ************************************************************ 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 ***********************************************************/ //Initialize variables double a, b, c, d; double first, outer, inner, last; char variable [32]; //Get values printf("what is the first coefficient? "); scanf("%lf",&a); printf("what is the first constant? "); scanf("%lf",&b); printf("what is the second coefficient? "); scanf("%lf",&c); printf("what is the second constant? "); scanf("%lf",&d); //Get possible variable printf("what is the variable?(enter 'none' if there is not one) "); scanf("%s", &variable); //FOIL the values first = a*c; outer = a*d; inner = b*c; last = b*d; //display answers if(strcmp(variable, "none") == 0) { //if we have no variable, then we add the numbers up printf("%lf", first + outer + inner + last); } else { //if we have a variable, we need to include it. printf("%lf*%s^2 + %lf*%s + %lf\n", first, variable, outer + inner, variable, last); }