Je ne suis pas sûr de ce que je fais mal. L'une des erreurs est que le rectangle est mentionné en premier dans int main()
. J'ai besoin du programme pour demander à l'utilisateur les dimensions de 2 rectangles et faire quelques calculs et retourner ces valeurs. Je veux aussi qu'il incorpore en quelque sorte les noms de structure dans le fichier d'en-tête. merciprogramme continue de s'écraser, d'autres problèmes avec le programme
rectangle2.h
struct rectangle
{
double length; // variable to store length
double width; // variable to store width
};
// function to calculate the area
double area( struct rectangle jane );
// function to calculate the perimeter
double perimeter(struct rectangle luis);
// function to calculate the diagonal length from one corner to another
double diagonal(struct rectangle adrian);
// function to determine if the rectangle is a square
// returns true when it is a square, false when it is not
bool isSquare(struct length fernie);
// function to determine whether the rectangle is golden
// https://en.wikipedia.org/wiki/Golden_rectangle
// (a + b)/a is equal to a/b
// returns true when it is a golden rectangle, false when it is not
bool isGolden(struct length claudia);
// function to determine if two rectangles are similar
// two rectangles are similar if the ratio of the length and width of
// one rectangle is equal to the ratio of the length and width of
// the other rectangle
bool areSimilar(struct rectangle pedro, struct rectangle omar);
rectangle.c
#include "rectangle2.h"
#include <stdio.h>
#include <stdbool.h>
double area(struct rectangle jane) //to calculate area of rectangle
{
return jane.width * jane.length;
}
double perimeter(struct rectangle luis) //to calculate perimeter of rectangle
{
return 2 * (luis.length + luis.width);
}
double diagonal(struct rectangle adrian) //to calculate diagonal of rectangle
{
return (adrian.length * adrian.length) + (adrian.width * adrian.width);
}
bool isSquare(struct length fernie ) //checks if rectangles are square
{
if((fernie.width * fernie.length) == (fernie.length * fernie.length))
return true;
else
return false;
}
bool isGolden(struct length claudia) //checks if rectangles are golden
{
if(((claudia.width + claudia.length)/claudia.width) == (claudia.width/claudia.length))
return true;
else
return false;
}
bool areSimilar(struct rectangle pedro, struct rectangle omar) //checks if rectangles are similar
{
if((pedro.length/pedro.width) == (omar.length/omar.width))
return true;
else
return false;
}
main.c
int main()
{
struct rectangle sides;
sides.length;
sides.width;
//asks the user for the length and width for 2 rectangles
printf("\nEnter dimensions of Rectangle 1: ");
printf("\nEnter Length: ");
scanf("%lf" , sides.length);
printf("\nEnter Width: ");
scanf("%lf" , sides.width);
printf("\nEnter dimensions of Rectangle 2: ");
printf("\nEnter Length: ");
scanf("%lf",sides.length);
printf("\nEnter Width: ");
scanf("%lf" , sides.width);
//printing statements after all calculations have been made
printf("\nArea of Rectangle 1 is: %lf" , area(&jane));
printf("\nArea of Rectangle 2 is: %lf",area(rectangle.jane));
printf("\nPerimeter of Rectangle 1: %lf" , perimeter(rectangle.rec1.luis));
printf("\nPerimeter of Rectangle 2: %f",perimeter(rectangle.rec2.luis));
printf("\nDiagonal of Rectangle 1: %lf" , diagonal(rectangle.rec1.adrian));
printf("\nDiagonal of Rectangle 2: %lf" , diagonal(rectangle.rec2.adrian));
return 0;
}
"Conserve les plantages" et "autres problèmes" ne sont pas vraiment descriptifs. Puis-je vous référer à e.g. https://ericlippert.com/2014/03/05/how-to-debug-small-programs/? – Evert
A première vue, votre programme ne peut même pas compiler: il y a une référence à une variable 'jane' dans' main() ', et un membre' jane' d'une structure 'rectange', les deux qui n'existent pas. – Evert
Ne compile même pas. Qu'est-ce que 'rectangle.jane' est supposé être dans' main() '? Il n'y a pas de variable nommée 'rectangle' dans' main() '. – AlexP