Thread: I am going to go Crazy PLease help

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    68

    Unhappy I am going to go Crazy PLease help

    Code:
    #include<stdio.h>
    #include<conio.h>
    
    int salesPersonNum[100];
    int Quarter1Total=0;
    int Quarter2Total=0;
    int Quarter3Total=0;
    int Quarter4Total=0;
    int Quarter=0;
    int Sales1[100];
    int Sales2[100];
    int Sales3[100];
    int Sales4[100];
    int count;
    int num=1;
    int i;
    
    int main()
    {    
         while(num!=0)
         {
         for(count=1; count>=1; count++)
         {
              printf("\nEnter the Sales Person's ID#: ");
              scanf("%d", &salesPersonNum[count]);
              
              printf("Enter the Quarter the sales took place(1-4): ");
              scanf("%d", &Quarter);
              while(Quarter>4)
              {
                   printf("Enter the Quarter the sales took place(1-4): ");
                   scanf("%d", &Quarter);
              }
              while(Quarter<1)
              {
                   printf("Enter the Quarter the sales took place(1-4): ");
                   scanf("%d", &Quarter);    
              }
              
              printf("Enter the Sales figure for the selected Quarter %d: ", Quarter);
              
              while(Quarter=1)
              {
                   scanf("%d", &Sales1[count]);
                   break;
              }
              while(Quarter=2)
              {
                   scanf("%d", &Sales2[count]);
                   break;
              }
              while(Quarter=3)
              {
                   scanf("%d", &Sales3[count]);
                   break;
              }
              while(Quarter=4)
              {
                   scanf("%d", &Sales4[count]);
                   break;
              }
              for(i=0; i<100; i++)
              {
                   Quarter1Total=Quarter1Total+Sales1[i];
                   Quarter2Total=Quarter2Total+Sales2[i];
                   Quarter3Total=Quarter3Total+Sales3[i];
                   Quarter4Total=Quarter4Total+Sales4[i];
              }              
              break;  
         }
         printf("Enter 0 to Summarize Data, 1 to Continue entering Data: ");
         scanf("%d", &num);
         }          
         printf("\nQuarter 1 Total = %d\n", Quarter1Total);
         printf("Quarter 2 Total = %d\n", Quarter2Total);                      
         printf("Quarter 3 Total = %d\n", Quarter3Total);
         printf("Quarter 4 Total = %d\n", Quarter4Total);
         getch();
         return 0;
    }
    what i am trying to do is let the user enter the Sales Person id and then enter the Quarter the sales took place, and then enter the amount of sales in that quarter and then the code will add the numbers for each of the quarters entered. ie it will add all of quarter 1's sales figure and then quarter 2's sales figure and so on.

    and then asks the user whether to continue entering data or summarize (display the Quater 1 results Quarter 2 results and so on.

    but it wouldn't work

    please help.
    -Ti22-

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Code:
    do {
      printf("Enter the Quarter the sales took place(1-4): ");
      scanf("%d", &Quarter);
    } while(Quarter < 1 && Quarter>4);
    Code:
    while(Quarter==1)

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    > int Sales1[100];
    > int Sales2[100];
    > int Sales3[100];
    > int Sales4[100];
    How about
    int Sales[4][100];

    Then you can do really neat things like
    scanf("%d", &Sales[Quarter][count]);
    and then you can cut out all that if ( Quarter type code.

    > for(count=1; count>=1; count++)
    This is going to be true for a long time...




    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  4. #4
    Registered User
    Join Date
    Dec 2003
    Posts
    14
    Originally posted by Monster
    Code:
    do {
      printf("Enter the Quarter the sales took place(1-4): ");
      scanf("%d", &Quarter);
    } while(Quarter < 1 && Quarter>4);
    Code:
    while(Quarter==1)
    Actually you would need an or statement instead of the and statement. (Quarter < 1 && Quarter > 4) will always evaluate to false.

  5. #5
    Senor Member nomi's Avatar
    Join Date
    Jan 2004
    Posts
    129
    Use 2-dimension arrays to neat things up...

    And use functions...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Is AOL music crazy?
    By joeprogrammer in forum A Brief History of Cprogramming.com
    Replies: 9
    Last Post: 03-24-2006, 07:24 PM
  2. restart drives me crazy
    By Jumper in forum A Brief History of Cprogramming.com
    Replies: 20
    Last Post: 03-17-2004, 12:52 PM
  3. crazy
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 23
    Last Post: 08-31-2002, 08:54 PM
  4. crazy output
    By asirep in forum C Programming
    Replies: 22
    Last Post: 04-09-2002, 11:41 AM
  5. Replies: 1
    Last Post: 02-24-2002, 06:24 PM