// Hrricane_2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include%26lt;cmath%26gt;
int main()
{int hlat, hlong, hspd; /*initialize vvariables for hurricane's */
int d; /*Assigns values*/
int FLLat = 26;
int FLLong = 80;
printf("Enter Hurricane's Latitude.\n");
scanf("%f",%26amp;hlat);
printf("Enter Hurricane's Longitude.\n");
scanf("%f",%26amp;hlong);
printf("Enter Huricane's speed.\n");
scanf("%f",%26amp;hspd);
d = sqrt((%d FLLat-%d hlat)*(%d FLLat-%d hlat) + (%d FLong-%d hlong)*(%d FLong-%d hlong));
return 0;
}
THE COMPILER DOES NOT LIKE THE d= LINE PLEASE HELP? HOW SHOULS IT BE WRITTEN
Formula in C?
There are so many errors in this program, I don't know where to begin. You need to go back and revise the basics of C. There are even errors that some compilers would miss.
1. When you use scanf with "%f", you must pass it a pointer to a variable of type float. Otherwise, it will still read in a floating point number but then generate instructions that interpret it as a value of type int.
2. If you want to do floating point calculations, you should generally stick to double precision. Don't even think of single precision--it's pretty useless.
3. Arithmetic expressions involve operators and operands. You seem to handle operators OK. Operands can be variables or numbers (there are other possibilities, but don't worry for now).
%d FFLat
is not a valid operand. What on earth are you thinking here?
4. The value you calculate for d is floating point. Why on earth are you assigning it to an integer?
5. You are calculating a value for d and then discarding it. Do you mean to print it out or what?
Reply:you should clear "%d"s from the line!
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment