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
Can anybody please provide me any suggestions why the compiler shows the following error:
expected identifier or '(' before numeric constant.
Thanks.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream f("bac.in");
long x,okp=0,oki=0,k=0, p=2,c=9999997;
while(f>>x) {
k++;
if((x%==0) && (x>=p)) {
okp++;
p=x;
}
else
if((x%2==1) && (x<=c)) {
oki++;
c=x;
}
}
if((okp+oki)==k)
cout<<"yes";
else
cout<<"no";
return 0;
}
Change (x%==0) to (x%2==0) on line 10.
Related
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
}
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 need to compare a character in a string that is in an array with another string. This is a functioning but simple version of my problem:
#include <iostream>
using namespace std;
int main() {
string a_ray[1] = {"asd"};
if (a_ray[0][0] == "a") {
bool a;
}
return 0;
}
Error message: ISO C++ forbids comparison between pointer and integer [-fpermissive]|
What causes this? And how can I do what I want to do in the correct way?
Thank you in advance!
Since you are comparing against a character, your code should be
if (a_ray[0][0] == 'a')
You are trying to compare a character with a character array, hence the error message.
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 wanted to test if the increment ++ works for the std::map :
#include <bits/stdc++.h>
using namespace std;
int main()
{
map<string, int> map;;
map['1'] = 0;
map['1']++;
cout << map['1'] << endl;
return 0;
}
And Ì get the error of the title for :
map['1'] = 0;
I do not understand why
In C++ '1' is a character, not a string literal, and your map has a key std::string, which is not same types. That is why the std::map::operator[] gave you the compiler error, it is mismatch type.
You need "" for mentioning it is a string literal.
map["1"] = 0;
Also, have a read:
Why is "using namespace std;" considered bad practice?
Why should I not #include <bits/stdc++.h>?
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.
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 9 years ago.
Improve this question
In the following piece of code I get the error mentioned below. Please tell me
Why *p=t gives error here
void reverse (char *p)
{
int length=strlen (p);
int c=0, i=length/2;
char *Temp=p+length-1, t;
while (c<length)
{
t=*Temp;
*Temp=*p
*p=t;
//Gives error as illegal, right operand has type char*
//Why is the error in the above line?
c++;
Temp--;
}
}
There is a semi-colon missing:
t=*Temp;
*Temp=*p ; //--here
*p=t;