Help with Intro Programming: Debugging Errors

Click For Summary

Discussion Overview

The discussion revolves around debugging errors in a C programming assignment related to calculating the distance between two points using the Distance Formula. Participants are helping to identify and correct syntax errors in the provided code.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • The original poster presents a code snippet and describes encountering a specific error related to the use of the 'float' keyword.
  • One participant suggests that the use of "float" is incorrect and implies that a variable name should be used instead.
  • Another participant emphasizes the importance of matching parentheses in the code and provides a corrected line of code as an example.
  • Further contributions reiterate the need for a variable name in place of "float" and highlight the parentheses issue again.
  • Suggestions are made to improve the readability of the output by adding newline characters in the printf statements.

Areas of Agreement / Disagreement

Participants generally agree on the need to replace "float" with a variable name and to ensure proper parentheses usage, but there is no consensus on the exact approach to resolve the errors.

Contextual Notes

The discussion does not resolve the underlying issues completely, as participants provide suggestions without confirming a definitive solution. There may be additional errors not addressed in the conversation.

Who May Find This Useful

Individuals learning C programming, particularly those struggling with syntax errors and debugging in introductory programming courses.

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.
 

Similar threads

Replies
7
Views
2K
Replies
14
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
6K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
4
Views
3K
Replies
47
Views
5K
  • · Replies 22 ·
Replies
22
Views
6K
Replies
2
Views
3K
  • · Replies 2 ·
Replies
2
Views
4K