why error showing: too few arguments to function? [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
Even on passing parameters to the function log, error showing too few arguments to function.
#include <iostream>
using namespace std;
int log(int n, int x){
return (n>1) ? 1 + log(n/x) : 0;
}
int main() {
int n,x;
cin>> n>> x;
cout<< log(n,x);
}
I expect the output of log10(1000) to be 3, but few arguments error is shown.

You forgot the second argument to your log function in the recursive step.
return (n>1) ? 1 + log(n/x, x) : 0;
By the way, you should name your variables something descriptive. For instance instead of using n perhaps use base.

Related

'cin' was not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 months ago.
Improve this question
I run my code and it gives an error 'cin' was not declared in this scope
My code
#include <bits/stdc++.h>
int m,a,b,c,d,e,f;
main()
{
cin>>m>>a>>b>>c>>d>>e>>f;
double g=a%b;
double h=c%d;
double k=e%f;
if (g<h && g<k){
int i=g;
}
if (h<g && h<k) {
int i=h;
}
if (k<g && k<h) {
int i=g;
}
double s=i*m;
cout<<s;
}
`
i think i wrote it right,help me
Use C++ standard library includes
#include <iostream>
then
std::cin
and
std::cout
If you do this, then you are writing portable and easy to read C++.
Even better, check that the data have been successfully read:
if (std::cin >> m >> a >> b>> c>> d>> e >> f){
// success - go on from here
}

Why can't the global variable delta be used in method of class? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I'm a beginner of C++. In this sample, I want to use the global variable delta in method update_v() of class neuron. But it can't be used. Could you tell me why if you know?
#include<iostream>
#include<cmath>
using namespace std;
unsigned long nextt=1;
long clock=0;
long delta=0;
class neuron{
public:
double a,b,c,d;
double current_v,current_u;
double previous_v,previous_u;
double accumulate;
void update_v(){
current_v=previous_v+delta(0.04*pow(previous_v,2)+previous_v)+accumulate;
}
void update_u(){
current_u=previous_u+delta*a*(b*previous_v-previous_u);
}
};
In void update_v(){, you do delta(0.04*pow(previous_v,2)+previous_v), so it makes the compiler thinks that you are calling a function named delta. But there's none, so it throws a error.
It looks like you forget to use the * operator:
void update_v(){
current_v = previous_v + delta * (0.04 * pow(previous_v,2) + previous_v) + accumulate;
}

cout was not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 2 years ago.
Improve this question
I'm new to C++ and coding entirely.
When I try to build my code it gives me "error: 'count' was not declared in this scope"
Everything I look up either tells me to add "using namespace std;" or add "int main()" but neither works for me.
#include <iostream>
using namespace std;
main()
{
int A = 4;
count << &A;
}
There is a typo in your identifier.
count should be cout.
Also, main should have the return type of int as it isn't standard C++ to automatically deduce the return type as int if not specified. In short, int main() is required.

Trying to create a cos(x) calculating function [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
I am coding a cos(x) function in C++ but the result I am getting is infinity, except that it should be -1/3.
Here is my code:
#include <iostream>
#include <math.h>
using namespace std;
The factorial function:
int factorial(unsigned int n)
{
unsigned long factorial = 1;
for(int o=1;o<=n;o++)
{
factorial *= o;
}
}
int main()
{
double x;
double answre;
double input;
cin>>input;
for(int i=0;i<2;i++)
{
double y=2*(i)+2;
I declared y here instead of implementing it's value directly, since I thought it is dividing by factorial instantaneously and that is the reason for all the parentheses as well.
x=((pow(input,2*(i)+2))/(factorial(y)))*(pow(-1,(i)+1));
x=+x;
}
answere=1+x;
cout<<answere<<endl;
return 0;
}
You are not returning anything in factorial
x=((pow(input,2*(i)+2))/(factorial(y)))*(pow(-1,(i)+1));
x=+x; // ???
If you want to add to x, just write x += .... What you did was assign one (!) summand to x and then set x to itself. You are never adding anything.

lambda function return type not working [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 6 years ago.
Improve this question
I have the following piece of code, and find that I'm not able to explicitly convert the output of lambda function into bool. I'm verifying this on the online IDE http://ideone.com/, and I choose C++14.
#include <iostream>
using namespace std;
int main() {
int number = 10;
int bar = 6;
auto numberisLarger = [&]() -> bool {return number > bar;};
bool isLarger = numberisLarger;
return 0;
}
However, I'm getting compilation error as below.
error: cannot convert 'main()::<lambda()>' to 'bool' in initialization
bool isLarger = numberisLarger;
I did explicitly convert it to bool, why it isn't working?
Thanks!
You need to execute the lambda, like you would a regular function.
bool isLarger = numberisLarger();