c4700 error, and c4474 warning

working on distance formula program for my CS1 class I think i'm close but running into a c4700 error on line 54 and a c4474 warning on line 72. i still need to put figure out how to put in a loop but any help solving these errors would be greatly appreciated. thanks in advance
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
Program prompts user to enter two points in the form (x1, y1) and (x2, y2) and finds the distance between the two points using a function.
Algorithm steps:
	1. Define a function called findDistance (...) that takes four parameters x1, y1 and x2, y2 as two points.
		a. finds the distance between them using the equation: sqrt//FIX ME sqrt symbol ((x2-x1)^2 + (y2-y1)^2)
		b. returns the calculated distance value
	2. Prompt user to enter four numbers
	3. Convert the values into float and store them into variables
	4. Call function getDistance by passing 4 entered numbers as arguments
	5. Display results with proper description.  Format output numbers to 2 decimal points.
	6. Test and validate that program output is correct for a given set of input points.
	7. Bonus - (10 points) Using a loop repeat step 2-6 until the user wants to quit.
*/


#include <iostream>
#include <cstdio>
#include <cassert>
#include <cmath>
using namespace std;

const double epsilon = 1e-6; // 0.000001 accuracy upto 6 decimal points

// function prototypes
// function that calculates the distance between two points
// x1, y1 and x2, y2 and returns the calculated value double findDistance (int, int, int, int);

// test function that runs automated testing void test();

double findDistance(int x1, int y1, int x2, int y2)
{
	cout << sqrt(pow(x2 - x1, 2) + (y2 - y1, 2)) << endl;
	//FIXME - Find the distance between (x1, y1) and (x2, y2)
	// following the algorithm step 1
	// return the calculated distance
	return 0.000000;
}

void test()
{
	assert(findDistance(4, 3, 5, 1) - 2.23607 <= epsilon);
	assert(findDistance(3, 5, 7, 0) - 6.40312 <= epsilon);
	assert(findDistance(-1, 2, 4, 18) - 16.76305 < epsilon);
	// FIXME - add atleast two more test cases
	cout << "all tests passed..." << endl;
}

	int main()

{
	double distance; 
	int x1, y1, x2, y2; // variables to store two points (x1, y1) and (x2, y2)
	char ch;
	distance = findDistance(x1, y1, x2, y2);

	//FIX ME - 10 bonus points - add loop until the user wants to quit
	system("cls");
	cout << "Program calculates distance between 2 points on a 2d Coordinates." << endl;
	cout << "Enter a point in the form (x, y) : ";
	// parse the input stream
	cin >> ch >> x1 >> ch >> y1 >> ch; // value stored in ch is ignored
	printf(" (x1, y1) = (%d, %d)\n", x1, y1);

	cout << "Enter a second point in the form (x, y): ";
	cin >> ch >> x2 >> ch >> y2 >> ch; // value store in ch is ignored
	printf(" (x2, y2) = (%d, %d)\n", x2, y2);
	//FIXME - Read/parse the second point and store data into variables x2 and y2 //fixed
	test();
	//FIXME - Call test function // fixed
	findDistance(x1, y1, x2, y2);
	//FIXME - call findDistance function passing proper arguments //
	printf("The distance between the 2 points =  ", distance);
	//FIXME - using printf function display the returned distance with proper description

	cin.ignore(1000, '\n');
	cout << "Good Bye!" << endl;
	cin.get();
	return 0;
}
Posting the error message instead of the error code is usually more useful.

Apparently c4700 is the error code for 'uninitialized local variables'. The problem is that you use x1, y1, x2 and y2 before you have assigned a value to them.

The compiler is giving you the c4474 warning because you are passing a double as argument but the string does not contain a format specifier (e.g. %f) that tells it where in the string you want that double to appear.
Last edited on
You are passing an uninitialized variable to findDistance(x1, y1, x2, y2). int x1, y1, x2, y2; should have some value. example x1 = 0; x2 =3; etc.....

* Google your error codes. 9/10 someone else has experience the same problem*
Topic archived. No new replies allowed.