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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T19:31:07+00:00 2026-06-14T19:31:07+00:00

I have declared a function (C++) int products(char num1, char num2, char num3, char

  • 0

I have declared a function (C++)

int products(char num1, char num2, char num3, char num4, char num5);

but my compiler is giving me this error:

Invalid conversion from 'char' to 'const Char*'
error initializing argument 1 of 'int atoi (const char*)'  on line 22

when I attempt to pass num1, num2 etc. as a parameter to atoi.

#include<iostream>
#include<string>

using namespace std;

int Product(char num1, char num2, char num3, char num4, char num5);

const string LargeNum = "7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450";

int main(){
int greatestVal = 0;
for(int i = 0; i + 4 <= LargeNum.length(); i++ ){
    if(greatestVal < Product(LargeNum[i], LargeNum[i+1], LargeNum[i+2], LargeNum[i+3], LargeNum[i+4])){
        greatestVal = Product(LargeNum[i], LargeNum[i+1], LargeNum[i+2], LargeNum[i+3], LargeNum[i+4]);
    }
}
cout << greatestVal << endl;
system("PAUSE");
}

int Product(char num1, char num2, char num3, char num4, char num5){
    return (atoi(num1)*atoi(num2)*atoi(num3)*atoi(num4)*atoi(num5));
}
  • 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-14T19:31:08+00:00Added an answer on June 14, 2026 at 7:31 pm

    atoi takes a const char* (i.e. a null terminated sequence of characters). You are supplying it with a single char, so the compiler complains. How you fix it depends on exactly what you are trying to do.

    I would guess that you want to convert a char representing a digit to an integer, ‘0’ to 0, ‘1’ to 1 etc. If so then the correct code would be

    return (num1 - '0')*(num2 - '0')*(num3 - '0')*(num4 - '0')*(num5 - '0');
    

    This works because chars convert to ints automatically when you do arithmetic on them, and also because the chars ‘0’ to ‘9’ are guaranteed to be in sequence, so all you need to do to convert a digit to an int is subtract ‘0’ from it.

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

Sidebar

Related Questions

I have this array declared inside my main() function: int VISITED[9][9]={{0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0}, {0,0,0,0,0,0,0,0,0},
I have a simple C function which I declare as: int strLen(const char* str_)
I have a variable declared at the top of my function as this.current_test =
I have written my own function, which in C would be declared like this,
I have a function declared like so: unsigned char** Classifier::classify(){ //... unsigned char **chars
I have declared some local variable in one function like this: void* thread_function (void*
I have a function declared as: int myFunction(const float** ppArr, const int n, const
I have declared and initialized two variables as shown below: int a=5; char* str;
I have declared an external function with a GCC weak attribute in a .c
Here I have declared another virtual function in Derived class. #include <iostream> using namespace

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.