I am trying to make a calculator!
I have been doing c++ for like a week and I thought I could do it.
Appartently I cannot.
Here is the source I wrote for the whole thing:
#include <iostream>
int multiply (int firstn, int secondn);
int divide (int firstn, int secondn);
int add (int firstn, int secondn);
int subtraction (int firstn, int secondn);
int main()
{
int choice;
int firstn;
int secondn;
int answer;
std::cout << "Choose which you wish to do: [multiply (1), divide (2), add (3), or subtract (4)]";
std::cin >> choice;
if (choice == 1)
std::cout << "\nEnter two numbers to multiply: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = multiply(firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 2)
std::cout << "\nEnter two numbers to divide(it will be rounded): ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = divide (firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 3)
std::cout << "\nEnter two numbers to add: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = subtraction (firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 4)
std::cout << "\nEnter two numbers to subtract: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = add(firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
return 0;
}
int multiply (int firstn, int secondn)
{
return (firstn * secondn);
}
int divide (int firstn, int secondn)
{
return (firstn / secondn);
}
int add (int firstn, int secondn)
{
return (firstn + secondn);
}
int subtraction (int firstn, int secondn)
{
return (firstn - secondn);
}
If you could figure what I am doing wrong it would be very appreciated
!
Thanks,
Denis
Ps: I DO NOT use Visual C++ so if you could help me in normal C++ it would be even cooler!
I have been doing c++ for like a week and I thought I could do it.
Appartently I cannot.
Here is the source I wrote for the whole thing:
#include <iostream>
int multiply (int firstn, int secondn);
int divide (int firstn, int secondn);
int add (int firstn, int secondn);
int subtraction (int firstn, int secondn);
int main()
{
int choice;
int firstn;
int secondn;
int answer;
std::cout << "Choose which you wish to do: [multiply (1), divide (2), add (3), or subtract (4)]";
std::cin >> choice;
if (choice == 1)
std::cout << "\nEnter two numbers to multiply: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = multiply(firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 2)
std::cout << "\nEnter two numbers to divide(it will be rounded): ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = divide (firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 3)
std::cout << "\nEnter two numbers to add: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = subtraction (firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
if (choice == 4)
std::cout << "\nEnter two numbers to subtract: ";
std::cin >> firstn;
std::cout << "\nSecond number: ";
std::cin >> secondn;
answer = add(firstn, secondn);
std::cout << "\n\nWOOOOLAHHHH! And the answer is: " << answer << "\n";
return 0;
}
int multiply (int firstn, int secondn)
{
return (firstn * secondn);
}
int divide (int firstn, int secondn)
{
return (firstn / secondn);
}
int add (int firstn, int secondn)
{
return (firstn + secondn);
}
int subtraction (int firstn, int secondn)
{
return (firstn - secondn);
}
If you could figure what I am doing wrong it would be very appreciated
Thanks,
Denis
Ps: I DO NOT use Visual C++ so if you could help me in normal C++ it would be even cooler!