1) I want to create a (ersatz of) solver, where a simple expression such as :
Revenue = Cost * (1 + GrossMargin)
would lead to 3 questions to the user :
- Revenue ?
- Cost ?
- GrossMargin ?
the user being asked to answer 2 out of those 3 questions, and the program calculating the third.
This is my (utter newbie) attempt :
//
// main.c
// LearningC
// Created by ThG on 19/10/13
//
#include <stdio.h>
int main(int argc, char *argv[])
{
// Variables
float Cost = 0;
float GrossMargin = 0;
float Revenue = 0;
// Ask the User
printf("What is your Revenue ? : ");
scanf("%f", &Revenue);
printf("What is your cost ? : ");
scanf("%f", &Cost);
printf("What is your Gross Margin goal ? : ");
scanf("%f", &GrossMargin);
// Equation
Revenue = Cost * (1 + GrossMargin);
// Nested ifs or expressions "Solver"
if (Revenue == 0)
{
printf("Your Revenue should be : %.2f $ * (1 + %.2f) = %.2f $\n", Cost, GrossMargin, Revenue);
}
else
{
if (Cost == 0)
printf("Your Cost should not be higher than : %.2f $ / (1 + %.2f) = %.2f $\n", Revenue, GrossMargin, Cost);
else
printf("Your GrossMargin is : %.2f $ / %.2f -1 = %.2f $\n", Revenue, Cost, GrossMargin);
}
return 0;
}
Of course, this failed miserably (btw, what does (lldb mean ?). How should I proceed ?
I hope this question is not irrelevant in StackOverflow's context. Should I precise that this is not homework (I am retired…) ?
2) I used to have on my (Jurassic) Palm Pilot a remarkable solver program called MathPad (by Rick Huebner, see http://www.palmspot.com/software/detail/ps52a_98295.html), maybe written in C.
Do you know if anything equivalent has been developed and maintained ?
Thanks in advance