- Joined
- May 8, 2007
- Messages
- 63
- Reaction score
- 0
Im writing a advanced calculator for a school project.
calculator.cpp (main file)
functions.cpp (all functions)
Removed all the advanced functions so it's more readable.
Quick explanation:
As you see it has a function for each task.
When the user enters in the string eg "addition", the function addition will be called.
But in the functions itself, at the end when the answer is printed, i have to use system("PAUSE"); so the user can see the answer. But when im using system("PAUSE"); it terminates the program, and I just want it to go back to int main().
So I dont know if it's possible to change the function system("PAUSE"); just for my use?
And no, I can't use cin.get(); as I'm already using cin, and I dont want the user to write something, and then enter, just only when the user press any key.
Tried alot of things now. still didn't work.
Any ideas?
calculator.cpp (main file)
Code:
#include <iostream>
#include <string>
#include "functions.cpp"
using namespace std;
int main()
{
string choice;
system("CLS");
system("TITLE Advanced Calculator :: Version 1.0");
system("COLOR 3");
cout << "[CLIENT] Program started" << endl;
cout << "\n";
cout << "[CLIENT] The requests are: " << endl;
cout << "[CLIENT] #01; 'addition' - Add two numbers." << endl;
cout << "[CLIENT] #02; 'subtraction' - Subtract two numbers." << endl;
cout << "[CLIENT] #03; 'multiply' - Multiply two numbers." << endl;
cout << "[CLIENT] #04; 'division' - Divide two numbers." << endl;
cout << "[CLIENT] #XX; 'exit' - Terminate the program." << endl;
cout << "\n";
cout << "[CLIENT] Enter a request:" << endl;
cout << "\n";
cout << "[REQUEST] ";
cin >> choice;
cout << "\n";
if(choice == "addition" || choice == "Addition" || choice == "ADDITION")
{
fcAddition();
}
if(choice == "subtraction" || choice == "Subtraction" || choice == "SUBTRACTION")
{
fcSubtraction();
}
if(choice == "multiply" || choice == "Multiply" || choice == "MULTIPLY")
{
fcMultiply();
}
if(choice == "division" || choice == "Division" || choice == "DIVISION")
{
fcDivision();
}
if(choice == "exit" || choice == "Exit" || choice == "EXIT")
{
fcExit();
}
return 0;
}
functions.cpp (all functions)
Code:
#include <iostream>
using namespace std;
void fcAddition(void);
void fcSubtraction(void);
void fcMultiply(void);
void fcDivision(void);
void fcExit(void);
void fcAddition()
{
int add_num1;
int add_num2;
cout << "[CLIENT] Enter the first number: ";
cin >> add_num1;
cout << "[CLIENT] Enter the second number: ";
cin >> add_num2;
cout << "\n";
cout << "[CLIENT] The answer is = " << add_num1+add_num2 << endl;
system("PAUSE");
}
void fcSubtraction()
{
int sub_num1;
int sub_num2;
cout << "[CLIENT] Enter the first number: ";
cin >> sub_num1;
cout << "[CLIENT] Enter the second number: ";
cin >> sub_num2;
cout << "\n";
cout << "[CLIENT] The answer is = " << sub_num1-sub_num2 << endl;
system("PAUSE");
}
void fcMultiply()
{
int mul_num1;
int mul_num2;
cout << "[CLIENT] Enter the first number: ";
cin >> mul_num1;
cout << "[CLIENT] Enter the second number: ";
cin >> mul_num2;
cout << "\n";
cout << "[CLIENT] The answer is = " << mul_num1*mul_num2 << endl;
system("PAUSE");
}
void fcDivision()
{
int div_num1;
int div_num2;
cout << "[CLIENT] Enter the first number: ";
cin >> div_num1;
cout << "[CLIENT] Enter the second number: ";
cin >> div_num2;
cout << "\n";
cout << "[CLIENT] The answer is = " << div_num1/div_num2 << endl;
system("PAUSE");
}
void fcExit()
{
system("EXIT");
}
Removed all the advanced functions so it's more readable.
Quick explanation:
As you see it has a function for each task.
When the user enters in the string eg "addition", the function addition will be called.
But in the functions itself, at the end when the answer is printed, i have to use system("PAUSE"); so the user can see the answer. But when im using system("PAUSE"); it terminates the program, and I just want it to go back to int main().
So I dont know if it's possible to change the function system("PAUSE"); just for my use?
And no, I can't use cin.get(); as I'm already using cin, and I dont want the user to write something, and then enter, just only when the user press any key.
Tried alot of things now. still didn't work.
Any ideas?
Last edited:


