Help with Intro Programming: Debugging Errors

In summary, the programmer is having difficulty understanding the code and is requesting help from others.
  • #1
andonibmp
2
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
  • #2
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.
 
  • #3
I have no idea what else to put there I keep getting errors.
 
  • #4
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:
  • #5
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.
 

1. What is debugging and why is it important in programming?

Debugging is the process of identifying and fixing errors or bugs in a computer program. It is important because even the smallest error can cause the entire program to fail, and debugging allows for a smooth and efficient execution of the program.

2. How do I approach debugging errors in my code?

The first step is to carefully read the error messages and try to understand what they are telling you. Then, review your code line by line and check for any syntax errors or typos. You can also use debugging tools such as breakpoints, which allow you to pause the program at a specific line of code to check its values and variables.

3. What are some common mistakes that lead to errors in programming?

Some common mistakes include typos, missing or incorrect syntax, using incorrect data types, and logic errors such as incorrect conditional statements or loops. It is also important to check for any missing or extra parentheses, brackets, or quotation marks.

4. How can I prevent errors in my code?

One way to prevent errors is to follow good coding practices, such as using descriptive variable names and commenting your code. It is also helpful to test your code frequently and in small chunks, rather than waiting until the end. Using debugging tools and writing test cases can also help catch errors before they become bigger problems.

5. What should I do if I am still unable to find and fix the error in my code?

If you are having trouble finding and fixing the error, it can be helpful to take a break and come back to it with a fresh perspective. You can also try explaining your code to someone else or seeking help from a more experienced programmer. Sometimes, it can also be beneficial to rewrite the code from scratch to identify and fix any underlying issues.

Similar threads

  • Programming and Computer Science
Replies
14
Views
2K
  • Programming and Computer Science
Replies
7
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
6
Views
5K
  • Programming and Computer Science
Replies
3
Views
993
  • Programming and Computer Science
Replies
32
Views
2K
  • Programming and Computer Science
Replies
4
Views
2K
  • Programming and Computer Science
2
Replies
47
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
873
  • Engineering and Comp Sci Homework Help
Replies
1
Views
8K
Back
Top