1

I have a Problem. I'm Trying to make a regular Calculator and Shape's Area and Perimeter finder.It's a combination. I didn't start on my Shape's Area and Perimeter Finder. This is My main.cpp.

 #include <iostream>
 #include <string>
 #include "AAPO.h" // Its a Header File.

using namespace std;

void Calculators_Operation();

int main()
{
    string opera;
    cout << "Do you want Arithmetic Calculator or Area and Perimeter Calculator" 
    << endl;

    cin >> opera;
    if (opera == "Arithmetic Calculator" or "arithmetic calculator" or "AC")
    {
        Calculators_Operation();
    }
    return 0;
}

This is my Operation Chooser.

#include <iostream>
#include <string>
#include "Arithmetic Chooser.h"

using namespace std;

void Calculators_Addition();
void Calculators_Subtraction();
void Calculators_Multiplication();
void Calculators_Division();

void Calculators_Operation()
{
    string answera;
    cout << "What Operation do you Want?" << endl;
    cin >> answera;
    if (answera == "Addition" or "addition" or "+");
    {
        Calculators_Addition();
    };
    if (answera == "Subtraction" or "subtraction" or "-");
    {
        Calculators_Subtraction();
    };
    if (answera == "Multiplication" or "multiplication" or "*" or "x" or "X")
    {
        Calculators_Multiplication();
    };
    if (answera == "Division" or "division" or "/")
    {
        Calculators_Division();
    };
    return;
}

This is my AAPO.h.

#ifndef AAPO_H_INCLUDED
#define AAPO_H_INCLUDED

void Calculators_Operation();

#endif // AAPO_H_INCLUDED

My Addition.

#include <iostream>
#include <string>

using namespace std;

void calculators_Addition_2();
void calculators_Addition_3();
void calculators_Addition_4();
void calculators_Addition_5();

void Calculators_Addition()
{
    //ADDITION COMPLETE
    string numberadd;
    cout << "How much numbers do you want?" << endl;
    cin >> numberadd;
    if (numberadd == "2")
    {
        calculators_Addition_2();
        return;
    };
    if (numberadd == "3")
    {
        calculators_Addition_3();
        return;
    };
    if (numberadd == "4")
    {
        calculators_Addition_4();
        return;
    };
    if (numberadd == "5")
    {
        calculators_Addition_5();
        return;
    }
}

void calculators_Addition_2()
{
    int add11;
    int add12;
    int sum;
    cout << "Enter the first number" << endl;
    cin >> add11;
    cout << "Enter the second number" << endl;
    cin >> add12;
    sum = add11 + add12;
    cout << "The sum of the numbers are " << sum << endl;
    return;
}

void calculators_Addition_3()
{
    int add13;
    int add23;
    int add33;
    int sum2;
    cout << "Enter the First Number" << endl;
    cin >> add13;
    cout << "Enter the Second Number" << endl;
    cin >> add23;
    cout << "Enter the Third Number" << endl;
    cin >> add33;
    sum2 = add13 + add23 + add33;
    cout << "The Sum of the Numbers are " << sum2 << endl;
    return;
}

void calculators_Addition_4()
{
    int add14;
    int add24;
    int add34;
    int add44;
    int sum3;
    cout << "Enter the First Number" << endl;
    cin >> add14;
    cout << "Enter the Second Number" << endl;
    cin >> add24;
    cout << "Enter the Third Number" << endl;
    cin >> add34;
    cout << "Enter the Fourth Number" << endl;
    cin >> add44;
    sum3 = add14 + add24 + add34 + add44;
    cout << "The Sum of the Numbers are " << sum3 << endl;
    return;
}

void calculators_Addition_5()
{
    int a15;
    int a25;
    int a35;
    int a45;
    int a55;
    int sum4;
    cout << "Enter the First Number" << endl;
    cin >> a15;
    cout << "Enter the Second Number" << endl;
    cin >> a25;
    cout << "Enter the Third Number" << endl;
    cin >> a35;
    cout << "Enter the Fourth Number" << endl;
    cin >> a45;
    cout << "Enter the Fifth Number" << endl;
    cin >> a55;
    sum4 = a15 + a25 + a35 + a45 + a55;
    cout << "The Sum of the Numbers are " << sum4 << endl;
    return;
}

My Subtraction.

#include <iostream>

using namespace std;

void Calculators_Subtraction()
{
    int subractify;
    int subracta;
    int differencea;
    cout << "Type in the First Number!" << endl;
    cin >> subractify;
    cout << "Type in the Second Number!" << endl;
    cin >> subracta;
    differencea = subractify - subracta;
    cout << "The Difference is " << differencea << endl;
    return;
}

My Multiplication.

#include <iostream>
#include <string>

using namespace std;

void Calculators_Multiplication_2();
void Calculators_Multiplication_3();
void Calculators_Multiplication_4();
void Calculators_Multiplication_5();

void Calculators_Multiplication()
{
    string multicipia;
    cout << "How much numbers do you want?" << endl;
    cin >> multicipia;
    if (multicipia == "2" or "Two" or "two")
    {
        Calculators_Multiplication_2();
    };
    if (multicipia == "3" or "Three" or "three")
    {
        Calculators_Multiplication_3();
    };
    if (multicipia == "4" or "Four" or "four")
    {
        Calculators_Multiplication_4();
    };
    if (multicipia == "5" or "Five" or "five")
    {
        Calculators_Multiplication_5();
    };
    return;
}

void Calculators_Multiplication_2()
{
    int multi2a;
    int multi2b;
    int product2;
    cout << "Type in the First Number." << endl;
    cin >> multi2a;
    cout << "Type in the Second Number." << endl;
    cin >> multi2b;
    product2 = multi2a * multi2b;
    cout << "The Product is " << product2 << "." << endl;
    return;
}

void Calculators_Multiplication_3()
{
    int multi3a;
    int multi3b;
    int multi3c;
    int product3;
    cout << "Enter the First Number!" << endl;
    cin >> multi3a;
    cout << "Enter the Second Number!" << endl;
    cin >> multi3b;
    cout << "Enter the Third Number!" << endl;
    cin >> multi3c;
    product3 = multi3a * multi3b * multi3c;
    cout << "The Product is" << product3 << "." << endl;
    return;
}

void Calculators_Multiplication_4()
{
    int multi4a;
    int multi4b;
    int multi4c;
    int multi4d;
    int product4;
    cout << "Enter the First Number!" << endl;
    cin >> multi4a;
    cout << "Enter the Second Number!" << endl;
    cin >> multi4b;
    cout << "Enter the Third Number!" << endl;
    cin >> multi4c;
    cout << "Enter the Fourth Number!" << endl;
    cin >> multi4b;
    product4 = multi4a * multi4b * multi4c * multi4d;
    cout << "The Product of the Numbers are " << product4 << "!" << endl;
    return;
}

void Calculators_Multiplication_5()
{
    int multi5a;
    int multi5b;
    int multi5c;
    int multi5d;
    int multi5e;
    int product5;
    cout << "Enter the First Number!" << endl;
    cin >> multi5a;
    cout << "Enter the Second Number!" << endl;
    cin >> multi5b;
    cout << "Enter the Third Number!" << endl;
    cin >> multi5c;
    cout << "Enter the Fourth Number!" << endl;
    cin >> multi5d;
    cout << "Enter the Fifth Number!" << endl;
    cin >> multi5e;
    product5 = multi5a * multi5b * multi5c * multi5d * multi5e;
    cout << "The Product of the Numbers are" << product5 << "!" << endl;
    return;
}

My Division.

#include <iostream>

using namespace std;

void Calculators_Division()
{
    float divisia;
    float divisiab;
    float quotient;
    cout << "Enter the Divisor" << endl;
    cin >> divisia;
    cout << "Enter the Dividend" << endl;
    cin >> divisiab;
    quotient = divisia / divisiab;
    cout << "The Quotient of the Numbers are " << quotient << endl;
    return;
}

The Problem right now is that when addition finishes , subtraction starts. After Subtraction, Multiplication. After Multiplication, Division. After That the program ends. I'm sorry. Its just that I'm new to programming (Like one month).

  • 10
    `if (multicipia == "2" or "Two" or "two")` will not do what you think. It's really just `if (1)` meaning do always. – drescherjm Jul 04 '17 at 15:54
  • 1
    Anyway, why are using alternative operator spellings instead of normal ones? – HolyBlackCat Jul 04 '17 at 16:01
  • 1
    This might not be easy, but you really need a [mcve]. This not only help the people read your problem easier, it also helps you debug – Passer By Jul 04 '17 at 16:02
  • `(addition|multiplication)(2|3|4|5)` - Why four different functions twice? You could read the desired number of operands within a for loop and sum them up immediately, this would easily allow for even more operands... – Aconcagua Jul 04 '17 at 16:11
  • The multicipia stuff was written to multiply with like 2 numbers . If you write "3" then with three numbers and so on and the "2" thing does work. I'm new too. So I am clueless. – Justin George Jul 05 '17 at 02:22

1 Answers1

0

There are many things to improve (some of them already mentioned in comments), but exact answer to your question is:

  • you have semicolon after your if-statement lines in Calculators_Operation() function body, which makes if-statements useless and your "operation" functions are being called every time (what you already noticed).
  • you use "or" operator in incorrect way, if you use (answera == "addition" or "+"), you basically say: ((answera == "addition) or "+") and that evaluates to true (see here)

EDIT: Your function Calculators_Operation may be changed to:

void Calculators_Operation()
{
   string answera;
   cout << "What Operation do you Want?" << endl;
   cin >> answera;

   if (answera == "Addition" || answera == "addition" || answera == "+")
   {
       Calculators_Addition();
   }
   else if (answera == "Subtraction" || answera == "subtraction" || answera == "-")
   {
       Calculators_Subtraction();
   }
   else if (answera == "Multiplication" || answera == "multiplication" || answera == "*" || answera == "x" || answera == "X")
   {
       Calculators_Multiplication();
   }
   else if (answera == "Division" || answera == "division" || answera == "/")
   {
       Calculators_Division();
   } else {
     cout << "Unknown operation entered!" << endl;
   }
}

NOTE: all your if statements need to be changed according to this function.

If anything does not work, please either put in comments what exactly does not work or edit your question with new code posting and question.

pe3k
  • 796
  • 5
  • 15
  • Thanks again for giving time to look into my problem. But I gave up on the Project. (Not that I am a quitter) I found it easier by doing the full thing as a loop. – Justin George Jul 25 '17 at 15:15