Maddie Wood Maddie Wood - 2 months ago 8
C++ Question

How to get rid of this error?

I was assigned to do a simple number converter, I followed all the instructions and they seemed pretty straight forward. This is for a beginner course into C++ and I seem to be missing the mark on this program. I continue to get an error stating that I need an initializer before double inputedNumber or that the variable is not in the scope. I have even compared my code to classmates and did what they did but this error still happens...
Any help would be awesome!
Thanks in advance!

#include <iostream>
using namespace std;
int main()
{
double inputedNumber;
cout << "Please input a decimal to be converted.";
cin >> inputedNumber;
cout << "Number Converter!! The given number is" << inputedNumber;
}

Answer
cin >> "Number Converter!! The given number is" >> inputedNumber;

does not compile, since cin is only for input not output; use cout instead!

cout << "Number Converter!! The given number is" << inputedNumber;

Also, if you really want to convert a number (to an integer for example) use this:

cout << "Number Converter!! The given number is" << static_cast<int>(inputedNumber);