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 8234111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:22:05+00:00 2026-06-07T18:22:05+00:00

This is C++ console snippet. I wish to call a fonction holding parameters amongst

  • 0

This is C++ console snippet.

I wish to call a fonction holding parameters amongst several function depending on user input.

For example:

#include<iostream>
using namespace std;

void Add (int x, int y)
    {
        cout << x + y << endl;
    }

void Subs (int x, int y)
    {
        cout << x - y << endl;
    }


int main(int argc, char* argv[])
{
    // Variable initialization
    char calc_type;
    int x;
    int y;

    // Console input
    cout << "Add or Substract (a or s)?" << endl;
    cin >> calc_type;
    cout << "1st number" << endl;
    cin >> x;
    cout << "2nd number" << endl;
    inc >> y;

    if (calc_type == "a")
    {
        Add(x, y);
    }
    else
    {
        Subs(x, y);
    }

return 0;

}

But in writing this I am returned error messages like the followings:

error C2446: ‘==’ : no conversion from ‘const char *’ to ‘int’

There is no context in which this conversion is possible

error C2040: ‘==’ : ‘int’ differs in levels of indirection from ‘const char [2]’

How can I cope with this problem (maybe references or pointers are preferred???)

Thank you

  • 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-07T18:22:06+00:00Added an answer on June 7, 2026 at 6:22 pm

    calc_type is a char variable. The constant “a” is a string. In C, char constants are in single quotes, not in double ones. So rephrase as:

    if (calc_type == 'a') 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have following code snippet: var reg = /^[0-9]$/; $('input[type=text]').keypress(function(){ console.log(reg.test(parseInt($(this).val()))); }); When I
Here's a snippet of the JS: ... $(this).load('html_fragment.html', function(data) { console.log(data); $(data).find('.accordion').accordion(); }); ...
I have the following snippet of code: $('input#teamName').live('blur', function() { var value = $(this).val();
After trying this simple console input with 5, the result is shown as 53
In the js code specified below - var tclass = function(){ this.func2=function(){console.log('func2')}; this.b={ func1:
Consider this code: var img = new Image(); img.onload = function() { console.log(this.width); };
Consider this code snippet: class Program { static void Main(string[] args) { Console.WriteLine(Test().ToString()); }
I'm trying to run this snippet in Python 3.1 console and I'm getting SyntaxError:
In the snippet below, I would like to call the change() function only if
The following snippet prints False : Console.WriteLine(Regex.IsMatch(abc, @[[:alpha:]])); But this prints True : Console.WriteLine(Regex.IsMatch(abc,

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.