I'm new to C++ and I'm studying out of a book (Game Programming - All In One, 2002) From what I've seen from other programs it's sort of out of date. Can someone tel me what's wrong with this?

-Error C2734: 'Value' : const object must be initialized if not extern

(It origionaly used std::cout and std::cin)

#include <iostream>
using namespace std;


main (void)
{
const float Value, FeetPerMeter = Value;
float Length1;
float Length2;
float Length3;


cout << "Enter the first lenght in meters: ";
cin >> Length1;
cout << "Enter the second length in meters: ";
cin >> Length2;
cout << "Enter the third lenght in meters: ";
cin >> Length3;


cout << "First length in feet is: " << Length1 * FeetPerMeter << endl;
cout << "Second length in feet is: " << Length2 * FeetPerMeter << endl;
cout << "Third length in feet is: " << Length3 * FeetPerMeter  << endl;


return 0;
}

This is what the book told me to insert, but it even looks incorrect to me. HMM, does anyone know what's wrong with this?

Well, I put in a number and then it worked not as i planed although. First i enterd the first, then the second, then the third. Then it just shuts the window concole.

Well, I put in a number and then it worked not as i planed although.

In the code you posted, Value does not have a value (as the error message tried to tell you).

First i enterd the first, then the second, then the third. Then it just shuts the window concole.

It sounds like an issue with the environment you are running it out of. Perhaps if you ran your program from a command line it would work as expected. But you may find a remedy by adding this line right before the 'return 0;' of main.

cin.get();

Explanation . Cure .

Don't use const(ant) float.Try using a normal float :D.
Once a constant is initialised it's value cant be changed AND you have to initialise a constant ALWAYS.

const float num = 10;
const float num1 = num;

The above will work. :!:

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.