D
D
Danyatuzat2015-03-31 12:44:47
visual studio
Danyatuzat, 2015-03-31 12:44:47

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

5 answer(s)
V
Vladimir Martyanov, 2015-03-31
@vilgeforce

The compiler wrote to you in Russian and white: an uninitialized variable is used. Specify what and where. Read compiler messages BEFORE asking questions.

A
Andrew, 2015-03-31
@Ashlst

I can be wrong. Haven't posted in a long time

#include
#include
#include

What did you connect??
cout << "Введите кол-во километров" << endl;
cin >> Kilometers;
Kilometers = Meters * Size;

Why enter and then overwrite the value of a variable??
double Kilometers;
double Meters;
double Santimeters;
double Milimeters;

Variables are uninitialized.
In general, some kind of hard-to-read code turned out (IMHO)

L
localghost, 2015-03-31
@localghost

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.

N
n3k0, 2015-03-31
@n3k0

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.

S
Skellig, 2015-04-02
@Skellig

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 question

Ask a Question

731 491 924 answers to any question