'cin' was not declared in this scope [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 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
}

Related

(cin >> int x ) showing error. why can't declare variable after cin [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
A very short program
#include <iostream>
using namespace std;
int main()
{
cin>> int x;
return 0;
}
it's not compiling, why can't declare after cin?
You first have to declare a variable before using it. Or in other words: Variables have to be in scope when using them. That's the way it works in C++.
cin is the object in c++ of class istream.
It is Used to accept the input from input devices like keyboard and
int x; is declaration of variable i.e. allocating the space where our number from input stream will get stored.>> is extraction operator which receives the stream.So declaration and taking input are 2 different things. 1) allocate memory(int x)2)write into it.
These 2 things won't happen together.

why error showing: too few arguments to 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 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.

c++ help me to understand why there is no output [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 3 years ago.
Improve this question
this program is simple :
1)take an input string .
2) convert it to long .
3) print convert result.
expected an output,but nothing found.
#include <stdio.h>
#include <string>
using namespace std;
int main()
{
string ch;
scanf("%s",ch);
long l=stol(ch);
printf("%l",l);
return 0;
}
Here's how it's done with C++ I/O. There's very little reason for using C I/O in a C++ program.
#include <iostream>
#include <string>
int main()
{
std::string input;
std::cin >> input; // take an input string
long lval = stol(str); // convert to long
std::cout << lval << '\n' // print the result
}
Now this stuff would be covered in the first chapter of any C++ book. A good book will greatly increase how quickly and how well you learn C++.

Code blocks error [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
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.

Returning boolean value does not print anything and doesn't show any compiler errors [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
This is a function to check a number for a power of two. Although the compiler does not print anything, it's also not showing any errors. Please let me know if the logic is correct or not.
Here is my code:
#include <bits/stdc++.h>
using namespace std;
bool isPowerofTwo(long long n)
{
// Your code here
for (int i = 1; i <=n; i<<1)
{
if(i==n){
return true;
}
}
return false;
}
int main()
{
cout << isPowerofTwo(2);
return 0;
}
The expression i<<1 in the third statement (the "iteration expression") of your for loop doesn't actually do anything (that is, it doesn't modify the value of i). You need, instead, i<<=1 (or, in 'long form', i = i << 1).
Also, please read: Why should I not #include <bits/stdc++.h>?. In your code, the only standard header you need is #include <iostream>. Another good post to read is: Why is "using namespace std;" considered bad practice?.