Answer the question
In order to leave comments, you need to log in
C++. I can't find the error in the program, tell me where is it?
#include
#include
#include
using std::cin;
using std::cout;
using std::endl;
int main()
{
setlocale( LC_ALL, "Russian");
const double Size = 1000;
double Kilometers;
double meters;
double Centimeters;
double Millimeters;
cout << "Enter number of kilometers" << endl;
cin >> Kilometers;
Kilometers = Meters * Size;
Meters = Santimeters * Size;
Santimeters = Millimeters * 10;
cout << "In " << Kilometers << "kilometers there are " << Meters << " meters\n" << endl;
cout << "In " << Meters << "meters - " << Santimeters << " centimeters\n" << endl;
cout << "There are " << Santimeters << "centimeters" << Milimeters << "millimeters\n" << endl;
_getch();
return 0;
}
__________________________________________________________________________________________________________
1>------ Build Started: Project: Project8, Configuration: Debug Win32 ------
1> main.cpp
1>c:\users\danyatuzat\documents\visual studio 2012\projects\project8 \project8\main.cpp(25): error C4700: uninitialized local variable 'Meters' used
1>c:\users\danyatuzat\documents\visual studio 2012\projects\project8\project8\main.cpp(26): error C4700: uninitialized local variable "Santimeters" used
1>c:\users\danyatuzat\documents\visual studio 2012\projects\project8\project8\main.cpp(27): error C4700: uninitialized local variable "Milimeters" used
========== Build: success: 0, errors: 1, no change: 0, skipped: 0 ==========
Answer the question
In order to leave comments, you need to log in
The compiler wrote to you in Russian and white: an uninitialized variable is used. Specify what and where. Read compiler messages BEFORE asking questions.
I can be wrong. Haven't posted in a long time
#include
#include
#include
cout << "Введите кол-во километров" << endl;
cin >> Kilometers;
Kilometers = Meters * Size;
double Kilometers;
double Meters;
double Santimeters;
double Milimeters;
Try to take on the role of the compiler and go through the program line by line from top to bottom.
What would you, as a compiler, have to calculate on line 25?
Edited: And ignore the harsh comment above. For some reason, it is not customary in Runet to help absolute beginners. It seems that the theory of mind does not work for people en masse and they consider any obvious thing to be obvious to everyone, and they take any attempt to find out something simple as an attempt to dump their work on someone else.
I am an amateur in crosses, but I would venture to suggest that after declaring variables, they (crosses) write some null or NaN or nothing at all into them.
Accordingly, the compiler in line 25 (and subsequent ones) chokes on the following:
Kilometers = Meters * Size
Kilometers you have initialized by hand, through cin.
Size at you the constant initialized at the declaration.
But in the variable Meters you have null / NaN / some other Mordor.
Correct me if I messed something up.
Distinguish between declaration (indicating the type and name) and initialization (assigning a value) to a variable. Memory for a variable is allocated not during declaration, but during initialization. If you thought that these variables were declared with a default numerical value of 0, then you were wrong - at the time of using Meters, Santimeters and Milimeters for the compiler simply do not exist. Good luck.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question