Search code examples
c++compiler-errorsiostreamdev-c++

When I run a C++ program, it returns some sort of number


I am a beginner in programming with C++.

I wrote a program, which must return 'number * 2':

#include <iostream>

int main()
{
    std::cout << 'Write a number: ';
    int x{};
    std::cin >> x;
    int y{ x * 2 };
    std::cout << 'Number * 2 = ' << y << '.';
    return 0;
}

When I hit F11 (start program), it always returns a long number.

I work in Dev C++.

Errors, that happened:

  • 5, 18 - [Warning] character constant too long for its type
  • 9, 18 - [Warning] character constant too long for its type

What's going on here, and how can I solve it?


Solution

  • Single quotes are for single characters. Double quotes are for strings. You should turn on your compiler warnings.