954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Error C2734: 'Value' : const obje

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
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?

.·)Tusky(·.
Newbie Poster
8 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 

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.

.·)Tusky(·.
Newbie Poster
8 posts since Jul 2004
Reputation Points: 10
Solved Threads: 0
 
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 .

Dave Sinkula
long time no c
Team Colleague
5,058 posts since Apr 2004
Reputation Points: 2,780
Solved Threads: 314
 

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. :!:

FireNet
Posting Whiz in Training
258 posts since May 2004
Reputation Points: 108
Solved Threads: 7
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You