Error with cin >>

I am learning C++ and I am using cin >> in online editors because I can’t download an IDE at other places. Here is my problem:

  • Whenever I use cin >>, it shows a garbage value instead of like input
  • Try this code in any online editor and it will show garbage instead of input
#include <iostream>
using namespace std;
int main(){
cout << "Enter values for x and y: "
double x;
double y;
cin >> x >> y;
cout << x + y;
return 0;
  • If I made mistakes in my code, please let me know.
  • If you find a solution please tell me.
    Thank you.

You haven’t terminated the first cout statement with semicolon.

And the code works pretty fine!

Either way it doesn’t work on any online compiler, What is the compiler you are using? I am using w3schools. And even though i put semicolon it still doesnt work

It’s strange that it doesn’t work on any online compiler! Any way I compiled your code at Programiz online C++ compiler.

Here is the link - Online C++ Compiler

Check it out!

1 Like