Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9223443
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:04:58+00:00 2026-06-18T04:04:58+00:00

I was making a simple calculator in C++. However the program does not completely

  • 0

I was making a simple calculator in C++. However the program does not completely function the way it should. When run, the trig if statement executes fine, however, the basic arithmetic else statement doesn’t work. I have determined that the code is not executing the else statement and was wondering how to fix it. The code inside the else statement works fine, as I have commented out the if statement. Help?

Here is my code:

#include "stdafx.h"
#include <iostream>
#include <string>
#include <cmath>


int main()
{
    double input = 0;
    double firstnumber = 0;
    double secondnumber = 0;


    std::string function;
    std::string operation;


    std::cout << "Enter your calculation: ";
    std::cin >> function;   


    if(function == "sin" || "cos" || "tan")
    {
        if(function == "sin")
        {
            std::cin >> input;
            std::cout << "The sine is " << sin(input) << std::endl;
            system("PAUSE");
        }
        else if(function == "cos")
        {
            std::cin >> input;
            std::cout << "The cosine is " << cos(input) << std::endl;
            system("PAUSE");

        }
        else if(function == "tan")
        {
            std::cin >> input;
            std::cout << "The tangent is " << tan(input) << std::endl;
            system("PAUSE");
        }
    }
    else
    {       

        firstnumber = ::atof(function.c_str());
        std::cin >> operation;
        std::cin >> secondnumber;


        double valueadd = firstnumber + secondnumber;
        double valuesubtract = firstnumber - secondnumber;
        double valuemultiply = firstnumber * secondnumber;
        double valuedivide = firstnumber / secondnumber;


        if(operation == "+")
        {      
            std::cout << " = " << valueadd << std::endl;
            system("PAUSE");
        }
        else if(operation == "-")
        {          
            std::cout << " = " << valuesubtract << std::endl;
            system("PAUSE");
        }
        else if(function == "*")
        {
            std::cout << " = " << valuemultiply << std::endl;
            system("PAUSE");
        }
        else if(function == "/")
        {
            std::cout << " = " << valuedivide << std::endl;
            system("PAUSE");
        }

        else
        {
            std::cout << "Error" << std::endl;
            return 0;
        }
    }
    return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:04:59+00:00Added an answer on June 18, 2026 at 4:04 am

    This line is wrong.

    if(function == "sin" || "cos" || "tan")
    

    It should be

    if((function == "sin") || (function == "cos") || (function == "tan"))
    

    Note that the check is actually meaningless because you already check for them each individually. You could tidy this up by doing this in a if, else if, else chain.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple program in C an Lisp arithmetic calculator just involving integers
I am currently making a simple calculator parser in Java, to deal only with
I'm making a simple Fahrenheit to Celcius number conversion function with a button and
I am making a simple layout for a calculator, actually i am new to
I am making a simple Android program that runs mnemonics or math exercises for
I want to make a simple program. Don't really care what it does, actually.
I'm making a simple tower defense game in Swing and I've run into a
I am making a Simple Calculator, I have added 0-9 Buttons ans well as
I come to this point when I was making a simple calculator. I did
I am making a little calculator in C, and i want to pass simple

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.