i just got back from work, so im gonna try to finish the program, i still dont get how it calls the function...
This is a discussion on Please help me figure this out for class, important. within the C++ Programming forums, part of the General Programming Boards category; i just got back from work, so im gonna try to finish the program, i still dont get how it ...
i just got back from work, so im gonna try to finish the program, i still dont get how it calls the function...
Post your latest effort.
> i still dont get how it calls the function...
Huh? You already written a call here
total = add (n1, n2);
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
so i talked to the professor and she helped me a bit. im pretty sure i have all the code i need written out, but i have mondo errors
[/code]
My Code:
Code:using namespace std; #include<iostream> #include<iomanip> double add (double num1, double num2); //add num1 to num2. double multiply (double num1, double num2); //multiply num1 and num2. double subtract (double num1, double num2); //subtract num2 from num1. double divide (double num1, double num2); //Divide num1 by num2. void display_stuff (double num1, double num2, double tot, char op); //Show equation. int main() { int x; double total, n1, n2; char letter; cout << "How many times would you like to run the program?" << endl; cin >> x; for (int i=1; i<=x; i++) { cout << "Enter a letter A, S, M, or D:" <<endl; cin >> letter; switch (letter) { case 'A' : cout << "Enter two real numbers to add:" << endl; cin >> n1 >> n2; display_stuff (n1, n2, total, '+'); total = add (n1, n2); break; case 'S' : cout << "Enter two real numbers to subtract:" << endl; cin >> n1 >> n2; display_stuff (n1, n2, total, '-'); total = subtract (n1, n2); break; case 'M' : cout << "Enter two real numbers to multiply:" << endl; cin >> n1 >> n2; display_stuff (n1, n2, total, '*'); total = multiply (n1, n2); break; case 'D' : cout << "Enter two real numbers to divide:" << endl; cin >> n1 >> n2; if (n2=0) cout << "Division by zero is not allowed." << endl; else { display_stuff (n1, n2, total, '/'); total = divide (n1, n2); } break; default: cout << "Must enter an A, M, S, or D!" << endl; break; } //End Switch } return 0; } double add (double num1, double num2) { double sum; sum = num1 + num2; return sum; } double multiply (double num1, double num2) { double sum; sum = num1 * num2; return sum; } double subtract (double num1, double num2) { double sum; sum = num1 - num2; return sum; } double divide (double num1, double num2) { double sum; sum = num1 / num2; return sum; } void display_stuff (double num1, double num2, double tot, char op) { cout << setiosflags (ios::fixed | ios::showpoint) << setprecision(2); cout << num1 << " " << op << " " << num2 << " = " << tot << endl; }
Last edited by WinterInChicago; 10-18-2006 at 05:18 PM.
Start with the first error. Fix it. Re-compile. Repeat.
Your first error is:
>> a5tyndall.cpp:8:18: iostram: No such file or directory
So, fix that (it should be obvious), then re-compile and continue until you get to an error you really cannot figure out.
disregard what was here, i fixed it, thanks for all the help guys and girls
Last edited by WinterInChicago; 10-18-2006 at 05:36 PM.