Answer the question
In order to leave comments, you need to log in
What is the logic error in the code?
Task: convert centimeters to meters. I want to do it through pointers.
#include <iostream>
using namespace std;
void main()
{
double *cm,*m;
cout << "Centimeters: ";
cin >> *cm;
*m = *cm / 100.;
while(1)
{
if(*cm <= 0)
{
cout << "incorrectly entered data\nInput centimeters again: ";
cin >> *cm;
}
else
{
printf("%d centimeters = %d meters",*cm,*m);
delete cm,m;
break;
}
}
system("pause");
}
Answer the question
In order to leave comments, you need to log in
A classic of the genre - writing to an uninitialized pointer.
Read the textbook for pointers better.
double *cm doesn't point anywhere. To indicate, you need to assign. For example, yes.
double* cm=new double.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question