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

  • Home
  • SEARCH
  • 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 8240299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:26:37+00:00 2026-06-07T20:26:37+00:00

Very new to coding, so please be understanding ;) I’m basically trying to make

  • 0

Very new to coding, so please be understanding 😉

I’m basically trying to make a calculator using the while loop, and if statements.

#include <iostream>

using namespace std;

int x = 1;
int number;
int total = 0;
int amt = 1;
int a;
int b;
int c;
int d;
string ans;

class OperateClass

I get the error: two or more data types in declaration of ‘main’

Please explain what this means/how to fix it.

I was also wondering if I need to make a new object for each function (Add, subtract, multiply, and divide)

Please help!

int main()
{

    cout << "Do you want to add, subtract, multiply or divide? I want to : " << endl;
    cin >> ans;

    if(ans == "add"){
        OperateClass opOper;
        opOper.add();

    }else{

        if(ans == "subtract"){
            OperateClass opOper
            opOper.subtract();
                }

    }else{

        if(ans == "multiply"){
            OperateClass opOper
            opOper.multiply();
        }

    }else{

        if(ans == "divide"){
            OperateClass opOper
            opOper.divide();

        }
    }

}

class OperateClass{
    public:
        int add(){
            while(x <= 3){
                cout << "Enter a number to use to add: " << endl;
                cin >> a;
                total = total + a;
                x++;
                amt++;
            }
        }

        int subtract(){
            while(x <= 3){
                cout << "Enter a number to use to add: " << endl;
                cin >> b;
                total = total - b;
                x++;
                amt++;
            }
        }

        int multiply(){
            while(x <= 3){
                cout << "Enter a number to use to add: " << endl;
                cin >> c;
                total = total * c;
                x++;
                amt++;
            }
        }

        int divide(){
            while(x <= 3){
                cout << "Enter a number to use to add: " << endl;
                cin >> d;
                total = total / d;
                x++;
                amt++;
            }
        }
}

int print(){
    cout << "Your total is: " << total << endl;

    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-07T20:26:38+00:00Added an answer on June 7, 2026 at 8:26 pm

    None of that code is valid. You begin a class definition with class OperateClass, but never end it and run right into main. A (simplified) class definition takes the form of:

    class [name] {
    
    };  // semi-colon terminates definition
    
    // so...
    
    class OperateClass {
    
    };  
    

    Next, you declare main… but it leads to an else branch (?).

    int main()
    {
    
        cout << "Do you want to add, subtract, multiply or divide? I want to : " << endl;
        cin >> ans;
    
        if(ans == "add"){
        OperateClass opOper;
        opOper.add();
    
    }else{  // what is this?
    

    Functions must also terminate via their closing brace, i.e.,

    int main() {
    
    }  // function is over!
    

    Now it looks like those may just be copy/paste errors. If that’s the case then you probably just forgot the semi-colon at the end of the class definition.

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

Sidebar

Related Questions

I am very new with VB coding, I am trying to save multiple excel
I'm very new to this, so please bear with me. For a coding C
I am very new to android, java and javascript coding. I am trying to
Im very new to all coding including jquery. I though this would have been
Very new to javascript and html-type stuff. I wanted to just make a quick
Very new to JQuery and MVC and webdevelopment over all. I'm now trying to
Very new to using Raphael.js I'm looking at the tutorials and I am able
Very new mobile developer here... I am trying to retrieve a list of tweets
I'm very new to OOP and am trying my hardest to keep things strictly
I'm coming from C# and very new at this so please bear with me.

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.