
Untitled
By: a guest on
Sep 18th, 2012 | syntax:
None | size: 1.45 KB | hits: 18 | expires: Never
/*
Program: Challenge 2
Author: Chapman Siu
Date: 5 Aug
Description:
Hello, coders! An important part of programming is being able to apply your programs,
so your challenge for today is to create a calculator application that has use in your
life. It might be an interest calculator, or it might be something that you can use in
the classroom. For example, if you were in physics class, you might want to make a
F = M * A calc.
EXTRA CREDIT: make the calculator have multiple functions!
Not only should it be able to calculate F = M * A, but also A = F/M, and M = F/A!
*/
#include <iostream>
#include <string>
using namespace std;
double f(int,int);
double a(int,int);
double m(int,int);
double f(int a, int m) {
return a*m;
}
double a(int f,int m) {
return f/m;
}
double m(int f, int a) {
return f/a;
}
int main()
{
int F, A, M ;
double ans;
string what;
cout << "What do you want to calculate?" <<endl;
cin >> what;
if (what == "f") {
cout << "What is the value of 'A'?" << endl;
cin >> A;
cout << "What is the value of 'M'?" << endl;
cin >> M;
ans = f(A,M);
}
if (what == "a") {
cout << "What is the value of 'F'?" << endl;
cin >> F;
cout << "What is the value of 'M'?" << endl;
cin >> M;
ans = a(F,M);
}
if (what == "m") {
cout << "What is the value of 'F'?" << endl;
cin >> F;
cout << "What is the value of 'A'?" << endl;
cin >> A;
ans = m(F,A);
}
cout << "The value of '"<<what<<"' is " << ans;
return 0;
}