-2

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

Vo Khoi
  • 1
  • 1
  • 6
    First of all, [Why should I not #include ?](https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h) – Some programmer dude Dec 16 '22 at 14:19
  • 3
    As for your problem, `cin` is in the `std` namespace, so you need to use `std::cin`. As taught by any decent [book](https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list), tutorial or class. – Some programmer dude Dec 16 '22 at 14:19
  • or `using namespace std;` – wojand Dec 16 '22 at 14:19
  • 7
    @wojand Except [Why is "using namespace std;" considered bad practice?](https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) – Some programmer dude Dec 16 '22 at 14:20
  • 2
    Welcome to Stack Overflow! Sounds like you could use a [good C++ book](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list). Your current usage of C++ will just give you bad habits if you continue on. – NathanOliver Dec 16 '22 at 14:20
  • And by the way, global variables (outside of any functions) should be avoided as well. And you need to read up more on scope. When you do `i * m` there's no such variable named `i`. And learn how to give your variables meaningful names. – Some programmer dude Dec 16 '22 at 14:22
  • 1
    Please do not use "that website" to teach you c++. It'll teach you awful habits and will _not_ make you a good programmer. You need a decent C++ book. – Mike Vine Dec 16 '22 at 14:22

1 Answers1

4

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
}
Bathsheba
  • 231,907
  • 34
  • 361
  • 483