Thread: so I need help in endng the loop from the input of the user before & after the loop

  1. #1
    Registered User
    Join Date
    Nov 2015
    Posts
    4

    so I need help in endng the loop from the input of the user before & after the loop

    Code:
    #define _CRT_SECURE_NO_WARNINGS
    #include <stdio.h>
    #define ENDPROCESS 0
    
    int
    main  (void)
    {
     int
      category = 0, numb_units=0, Total_Units=0, numb_cases=1, total_cases=0, numb_units1=0, numb_units2=0, numb_units3=0, numb_units4=0, numb_units5=0, cases=0;
     
     double WholeSalePrice1 = 0.0, WholeSalePrice2 = 0.0, WholeSalePrice3 = 0.0, WholeSalePrice4 = 0.0, WholeSalePrice5 = 0.0, Total_WholesalePrice = 0.0;
     
     printf("Enter the number of cases received for the toy product (or %d to quit):", ENDPROCESS);
     scanf("%d", &numb_cases);
     
     
     while (numb_cases > 0) {
      printf("Enter the number of cases received for the toy product (or %d to quit):", ENDPROCESS);  
      scanf("%d", &numb_cases);
      total_cases+=numb_cases;
      
     printf("Toy product sales Category: ");
     scanf("%d", &category);
      
      while (category < 1 || category >5) {
     printf("Category is invalid, please enter between 1 & 5:");
     scanf("%d", &category);
      }
      if (category==1) {
      
     printf("Wholesale Price of toy case: $");
     scanf("%lf", &WholeSalePrice1);
      
     
      while (WholeSalePrice1 <= 0);{
     printf("Wholesale price invalid, please enter value greater than 0:");
     scanf("%lf", &WholeSalePrice1);
      }
     printf("Number of toy units per case: ");        
     scanf("%d", &numb_units1);
      
      while (numb_units1 <=0) {
     printf("Number of units invalid, please enter number greater than 0:");
     scanf("%d", &numb_units1);
      } 
     Total_WholesalePrice+=WholeSalePrice1;
     Total_Units+=numb_units1;
      }
      
      else if(category==2) {
     printf("Wholesale Price of toy case: $");
     scanf("%lf", &WholeSalePrice2);
      
     
      while (WholeSalePrice2 <= 0) {
     printf("Wholesale price invalid, please enter value greater than 0:");
     scanf("%lf", &WholeSalePrice2);
      }
      
     printf("Number of toy units per case: ");        
     scanf("%d", &numb_units2);
      
      while (numb_units2 <=0) {
     printf("Number of units invalid, please enter number greater than 0:");
     scanf("%d", &numb_units2);
      }  
     Total_WholesalePrice+=WholeSalePrice2;
     Total_Units+=numb_units2;
       }  
       
       
      else if(category==3) {
     printf("Wholesale Price of toy case: $");
     scanf("%lf", &WholeSalePrice3);
      
     
      while (WholeSalePrice3 <= 0); {
     printf("Wholesale price invalid, please enter value greater than 0:");
      scanf("%lf", &WholeSalePrice3);
      }
     printf("Number of toy units per case: ");        
     scanf("%d", &numb_units3);
      
      
      while (numb_units3 <=0) {
     printf("Number of units invalid, please enter number greater than 0:");
     scanf("%d", &numb_units3);}
      
     Total_WholesalePrice+=WholeSalePrice3;
     Total_Units+=numb_units3;
       } 
       
      else if(category==4) {
     printf("Wholesale Price of toy case: $");
     scanf("%lf", &WholeSalePrice4);
      
     
      while (WholeSalePrice4 <= 0) {
     printf("Wholesale price invalid, please enter value greater than 0:");
     scanf("%lf", &WholeSalePrice4);
      }
     printf("Number of toy units per case: ");        
     scanf("%d", &numb_units4);
      
      while (numb_units4 <=0) {
     printf("Number of units invalid, please enter number greater than 0:");
     scanf("%d", &numb_units4);
      }
      
     Total_WholesalePrice+=WholeSalePrice4;
     Total_Units+=numb_units4;
       }
       
     
       else if(category==5) {
     printf("Wholesale Price of toy case: $");
     scanf("%lf", &WholeSalePrice5);
      
     
      while (WholeSalePrice5 <= 0) {
     printf("Wholesale price invalid, please enter value greater than 0:");
     scanf("%lf", &WholeSalePrice5);
      }
     printf("Number of toy units per case: ");        
     scanf("%d", &numb_units5);
      
      while (numb_units5 <=0) {
     printf("Number of units invalid, please enter number greater than 0:");
     scanf("%d", &numb_units5);
      }
     Total_WholesalePrice+=WholeSalePrice5;
     Total_Units+=numb_units5;
        }
        }
     
     
     printf("Warehouse Shipping Processing Complete\n\n");
     printf("Total Cases Received at Warehouse: %4.2d\n", total_cases);
     printf ("Total Toy Units Received at Warehouse: %4.2d\n", Total_Units);
     printf("Total Wholesale Cost of Shipments Received: $ %4.2f\n\n", Total_WholesalePrice);
     printf("Total Sales Category 1 Toy Units Received: %4.2d\n",numb_units1);
     printf("Total Sales Category 1 Wholesale Cost Received: $%4.2f\n\n", WholeSalePrice1);
     printf("Total Sales Category 2 Toy Units Received: %4.2d\n",numb_units2);
     printf("Total Sales Category 2 Wholesale Cost Received: $%4.2f\n\n", WholeSalePrice2);
     printf("Total Sales Category 3 Toy Units Received: %4.2d\n",numb_units3);
     printf("Total Sales Category 3 Wholesale Cost Received: $%4.2f\n\n", WholeSalePrice3);
     printf("Total Sales Category 4 Toy Units Received: %4.2d\n",numb_units4);
     printf("Total Sales Category 4 Wholesale Cost Received: $%4.2f\n\n", WholeSalePrice4);
     
     printf("Total Sales Category 5 Toy Units Received: %4.2d\n",numb_units5);
     printf("Total Sales Category 5 Wholesale Cost Received: $%4.2f\n", WholeSalePrice5);
     
     return (0);
     }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Do you have a specific question or problem?

    You really really need to consistently use some indentation style. The way your program is presently presented it is very hard to read, and almost impossible to follow your logic.


    Jim

  3. #3
    Registered User
    Join Date
    Nov 2015
    Posts
    4
    A problem. In other words... how do I properly write a sentinel loop?

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Where do you want this loop? You already have several loops with sentinel values, is there something wrong with them?

    Jim

  5. #5
    Registered User
    Join Date
    Nov 2015
    Posts
    4
    Want it to come right after the 1st print function each time it loops

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Infinete loop asking user for input
    By telmo_d in forum C Programming
    Replies: 4
    Last Post: 07-22-2015, 12:23 PM
  2. Average of user input in a loop problem
    By tadm123 in forum C Programming
    Replies: 11
    Last Post: 10-03-2012, 10:53 AM
  3. User input while loop is running
    By two31d in forum C++ Programming
    Replies: 7
    Last Post: 11-30-2005, 05:28 PM
  4. user input loop
    By asudave2302 in forum C++ Programming
    Replies: 11
    Last Post: 12-21-2004, 09:45 PM
  5. Getting user input for filename loop
    By jpchand in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2003, 06:37 AM

Tags for this Thread