Help with Intro Programming: Debugging Errors

AI Thread Summary
The discussion centers on troubleshooting errors in a C programming code snippet. The primary issue arises from a syntax error in the assignment of the distance variable. The code incorrectly uses "float" instead of a variable name for the assignment, leading to the error message. The correct line should be "distance = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));" ensuring that a variable is assigned a value rather than a data type. Additionally, there are parentheses mismatches that need correction. Suggestions are made to improve code readability by adding newline characters in the printf statements to reduce clutter. Overall, the focus is on correcting variable assignments and ensuring proper syntax for successful code execution.
andonibmp
Messages
2
Reaction score
0
hey I am doing a intro programming class and I am running into some problems. would really appreciate some help to see where I went wrong. Been trying to figure it out for hours now. Someone please help me out
These are my errors
c: In function ‘main’:
c:33:9: error: expected identifier or ‘(’ before ‘=’ token



This is the code:

#include <stdio.h>
#include <math.h>


int main (void)
{
float distance;


int x1,x2;
int y1,y2;

printf("The three types of angles in triangles are: Right angles,Obtuse Angles, and Acute angles") ;

printf("Three kinds of triangles are: Equilateral Triangles,Isosceles Triangles and Scalene Triangles") ;

printf(" The Pythagorean Theorem is : a2+b2=c2") ;

printf("The Distance Formula is: sqrt(pow(x2-x1,2) + pow(y2-y1,2)") ;

printf("Please enter First X value") ;
scanf("%d",&x1) ;

printf("Please enter Second X Value") ;
scanf("%d",&x2) ;

printf("please enter First Y Value") ;
scanf("%d",&y1) ;

printf("Please enter Second Y Value") ;
scanf("%d",&y2) ;

float=sqrt(pow(x2-x1,2) + pow(y2-y1,2);


printf("Distance is %f",distance);

return 0;
}
 
Technology news on Phys.org
andonibmp said:
float=sqrt(pow(x2-x1,2) + pow(y2-y1,2);

I think you meant to put something other than "float" there. Also, check your parentheses while you're at it.
 
I have no idea what else to put there I keep getting errors.
 
float is a data type you need to use a variable name of type float, also make sure your parens are equal to each other for example this

distance=sqrt(pow(x2-x1,2) + pow(y2-y1,2));

P.S. throw some '\n' in your printf statements so it is not as cluttered.
 
Last edited:
andonibmp said:
I have no idea what else to put there I keep getting errors.
Put a variable there.

You can't assign a value to a data type.

Also, see jtbell's post - you have a problem with your parentheses on that line.
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top