fork download
  1. #include <stdio.h>
  2. #include <float.h>
  3.  
  4. struct Book {
  5. char title[100];
  6. char author[100];
  7. float price;
  8. };
  9.  
  10. int main() {
  11. struct Book book1, book2, book3;
  12.  
  13. printf("\tInput Details for Three Books:\n\tBOOK 1 DETAILS\n");
  14. printf("\t\tTitle: ");
  15. fgets(book1.title, sizeof(book1.title), stdin);
  16.  
  17. printf("\n\t\tAuthor: ");
  18. fgets(book1.author, sizeof(book1.author), stdin);
  19.  
  20. printf("\n\t\tPrice: $");
  21. scanf("%f", &book1.price);
  22. getchar();
  23.  
  24. printf("\n\n\tBOOK 2 DETAILS\n");
  25. printf("\t\tTitle: ");
  26. fgets(book2.title, sizeof(book2.title), stdin);
  27.  
  28. printf("\n\t\tAuthor: ");
  29. fgets(book2.author, sizeof(book2.author), stdin);
  30.  
  31. printf("\n\t\tPrice: $");
  32. scanf("%f", &book2.price);
  33. getchar();
  34.  
  35. printf("\n\n\tBOOK 3 DETAILS\n");
  36. printf("\t\tTitle: ");
  37. fgets(book3.title, sizeof(book3.title), stdin);
  38.  
  39. printf("\n\t\tAuthor: ");
  40. fgets(book3.author, sizeof(book3.author), stdin);
  41.  
  42. printf("\n\t\tPrice: $");
  43. scanf("%f", &book3.price);
  44. getchar();
  45.  
  46. struct Book mostExpensive;
  47. if (book1.price >= book2.price && book1.price >= book3.price) {
  48. mostExpensive = book1;
  49. } else if (book2.price >= book1.price && book2.price >= book3.price) {
  50. mostExpensive = book2;
  51. } else
  52. mostExpensive = book3;
  53.  
  54. struct Book lowestPriced;
  55. if (book1.price <= book2.price && book1.price <= book3.price) {
  56. lowestPriced = book1;
  57. } else if (book2.price <= book1.price && book2.price <= book3.price) {
  58. lowestPriced = book2;
  59. } else
  60. lowestPriced = book3;
  61.  
  62. printf("\nMost Expensive Book: \n");
  63. printf("Title: %s\n", mostExpensive.title);
  64. printf("Author: %s\n", mostExpensive.author);
  65. printf("Price: %.2f\n", mostExpensive.price);
  66.  
  67. printf("\nLeast Expensive Book: \n");
  68. printf("Title: %s\n", lowestPriced.title);
  69. printf("Author: %s\n", lowestPriced.author);
  70. printf("Price: %.2f\n", lowestPriced.price);
  71.  
  72. return 0;
  73. }
Success #stdin #stdout 0s 5276KB
stdin
Standard input is empty
stdout
	Input Details for Three Books:
	BOOK 1 DETAILS
		Title: 
		Author: 
		Price: $

	BOOK 2 DETAILS
		Title: 
		Author: 
		Price: $

	BOOK 3 DETAILS
		Title: 
		Author: 
		Price: $
Most Expensive Book: 
Title: 
Author: 
Price: 0.00

Least Expensive Book: 
Title: 
Author: 
Price: 0.00