Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* NAME: James Toste
- PURPOSE: The program takes in the number of volumes and price per stated volumes for three book collections, as well as the budget of the buyer. It then prints various information about the situation.
- DATE: 9/20/2017 */
- #include <stdio.h>
- int main(void)
- {
- int col1n, col1p, col2n, col2p, col3n, col3p, bobbdgt, col1tp, col2tp, col3tp, col123tp, i, p, k, j;
- //---#n means number, ---#p means price, ---#tp means total price//
- printf("Enter volumes and price per volume for collection 1: ");
- scanf("%d %d", &col1n, &col1p);
- printf("Enter volumes and price per volume for collection 2: ");
- scanf("%d %d", &col2n, &col2p);
- printf("Enter volumes and price per volume for collection 3: ");
- scanf("%d %d", &col3n, &col3p);
- printf("Enter Bob's budget: ");
- scanf("%d", &bobbdgt);
- if (bobbdgt > 0)
- {
- printf("(1) Bob has some money to buy collections.\n");
- }
- else
- {
- printf("(1) Bob does not have money to buy anything.\n");
- }
- col1tp = col1n * col1p;
- col2tp = col2n * col2p;
- col3tp = col3n * col3p;
- col123tp = col1tp + col2tp + col3tp;
- if (bobbdgt >= col123tp)
- {
- printf("(2) Bob has enough money to buy all three collections.\n");
- }
- else
- {
- printf("(2) Bob does not have enough money to buy all three collections.\n");
- }
- /*##########################################
- Here begins the if/else statements for (3)
- ########################################## */
- i = 0;
- if (bobbdgt <= col1tp)
- {
- i += 1;
- }
- else
- {
- i += 0;
- }
- if (bobbdgt <= col2tp)
- {
- i += 1;
- }
- else
- {
- i += 0;
- }
- if (bobbdgt <= col3tp)
- {
- i += 1;
- }
- else
- {
- i += 0;
- }
- if (i >= 2)
- {
- printf("(3) At least two collections are more expensive than Bob's budget.\n");
- }
- else
- {
- printf("(3) At least two collections are cheaper than or equal to Bob's budget.\n");
- }
- /*##########################################
- Here begins the if/else statements for (4)
- ########################################## */
- p = 0;
- if (col1tp == col2tp)
- {
- p += 1;
- }
- else
- {
- p += 0;
- }
- if (col1tp == col3tp)
- {
- p += 1;
- }
- else
- {
- p += 0;
- }
- if (col2tp == col3tp)
- {
- p += 1;
- }
- else
- {
- p += 0;
- }
- if (p >= 1)
- {
- printf("(4) At least two collections cost the same amount of money.\n");
- }
- else
- {
- printf("(4) No two collections have the same price.\n");
- }
- /*##########################################
- Here begins the if/else statements for (5)
- ########################################## */
- k = 0;
- if (col1tp <= bobbdgt)
- {
- k += 1;
- }
- else
- {
- k += 0;
- }
- if (col2tp <= bobbdgt)
- {
- k += 1;
- }
- else
- {
- k += 0;
- }
- if (col3tp <= bobbdgt)
- {
- k += 1;
- }
- else
- {
- k += 0;
- }
- if (k == 1)
- {
- printf("(5) Only one collection is cheaper than or equal to Bob's budget.\n");
- }
- else
- {
- printf("(5) More than one collection is cheaper than or equal to Bob’s budget or they are all more expensive.\n");
- }
- /*##########################################
- Here begins the if/else statements for (6)
- ########################################## */
- j = 0;
- if (bobbdgt >= col1tp)
- {
- j += 1;
- }
- else
- {
- j += 0;
- }
- if (bobbdgt >= col2tp)
- {
- j += 1;
- }
- else
- {
- j += 0;
- }
- if (bobbdgt >= col3tp)
- {
- j += 1;
- }
- else
- {
- j += 0;
- }
- if (j == 3)
- {
- printf("(6) Bob has enough money to buy any one of the three collections.\n");
- }
- else
- {
- printf("(6) Bob does not have enough money to buy any one of the three collections.\n");
- }
- /*##########################################
- Here begins the if/else statements for (7)
- ########################################## */
- if (j == 0)
- {
- printf("(7) Bob does not have enough money to buy any collection.\n");
- }
- else
- {
- printf("(7) Bob can buy at least one collection.\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement