Ich bin nicht sicher, was ich falsch mache. Einer der Fehler ist, dass das Rechteck zuerst in Int main()
erwähnt wird. Ich brauche das Programm, um den Benutzer nach den Dimensionen von 2 Rechtecken zu fragen und einige Berechnungen zu machen und diese Werte zurückzugeben. Ich möchte auch, dass es irgendwie die Strukturnamen in die Header-Datei einbaut. dankeProgramm stürzt immer wieder ab, andere Probleme mit Programm
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;
}
"Keeps Absturz" und "andere Probleme" sind nicht wirklich beschreibend. Darf ich Sie auf z.B. https://ericlippert.com/2014/03/05/how-to-debug-small-programs/? – Evert
Auf den ersten Blick kann Ihr Programm nicht einmal kompilieren: Es gibt einen Verweis auf eine 'jane'-Variable in' main() ', und ein' jane'-Mitglied einer 'rectange'-Struktur, die beide nicht existieren. – Evert
Kompiliert nicht einmal. Was soll 'rectangle.jane' in' main() 'sein? Es gibt keine Variable mit dem Namen 'rectangle' in' main() '. – AlexP