Thread: CLOSE PROGRAM problem

  1. #1
    Registered User
    Join Date
    Mar 2013
    Posts
    5

    CLOSE PROGRAM problem

    Need help for my project. Everytime I run the file when it comes to the part of displaying all the user input, only the ordered item,quantity,and total amount of purchased was being displayed.The rest such as the name,address,postal code,contact number,email add,mode of payment and claim item through appears <null>..What's wrong with this...I need an answer badly please help..

    Code:
    #include<stdio.h>
    
    
    main()
    {
            
          int item_code, quantity;
          double tprice;
          char ans, y;
               
               
          //Display Welcome
          printf("\n\t*****************************************************************\n\t*\t\t\t\t\t\t\t\t*\n\t*");
          printf("\t     ::::: WELCOME TO PILLOW <^.^> HOUSE :::::\t\t*\n\t*\t\t\t\t\t\t\t\t*\n\t*");
          printf("****************************************************************\n\n");
          printf("\n\n\tPillow <^.^> House offers varieties of pillows that you can use\n\teverywhere.");
          printf("You can use them with full comfort because our items\n\tare made of 100 percent fiber and the fabric used");
          printf(" is pure cotton.");
          printf("\n\nPlease select your order in the list of items below: ");
          printf("\n\nPrice \t\tItem Code \t\tName of Item");
          printf("\n\n349.00 \t\t   1 \t\t\tDream Pillow");
          printf("\n\n349.00 \t\t   2 \t\t\tBolster Pillow");
          printf("\n\n549.00 \t\t   3 \t\t\tFantasy Pillow");
          printf("\n\n599.00 \t\t   4 \t\t\tHealth Pillow");
          
          //Enter item Code 
          
          printf("\n\n\nEnter the item code: ");
          scanf("%d", &item_code);
          
           if ((item_code>0)&&(item_code<5)){
               printf("\nEnter Item Quantity: ");
               scanf("%d", &quantity);
               
               switch(item_code){
                 case 1: 
                      printf("\nOrdered Item: DREAM PILLOW");
                      tprice = 349.00 * quantity;
                      break;
                 case 2: 
                      printf("\nOrdered Item: BOLSTER PILLOW");
                      tprice = 349.00 * quantity;
                      break;
                 case 3:
                      printf("\nOrdered Item: FANTASY PILLOW"); 
                      tprice = 549.00 * quantity;
                      break;
                 case 4:
                      printf("\nOrdered Item: HEALTH PILLOW"); 
                      tprice = 599.00 * quantity;
                      break;
                      }
               }else {
                printf("Invalid Input!");
                getch();
                exit(0);
                }
           //Prompt Do you wish to continue
               printf("\n\nDo you wish to continue?: y/n\n");
               scanf("%s", &ans);
                
               if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
                  
                  { exit(0);}
                  
                 else 
                   
                  { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
                           
           //Display Personal Info                   
                   char name, address, pcode, contact, e_add;
                   char mop, date, a;
                   
                   printf("Please fill up your personal information");
                   printf("\n\nComplete Name: ");
                   scanf("%s", &name);
                   printf("Complete Address: ");
                   scanf("%s", &address);
                   printf("Postal Code: ");
                   scanf("%s", &pcode);
                   printf("Contact No: ");
                   scanf("%s", &contact);
                   printf("E-mail address: ");
                   scanf("%s", &e_add);
           
          // Enter Code
                  
                   printf("\n*********************************************");
                   printf("\n\nMode of Payment \tCode");
                   printf("\n\nBank Deposit \t\tA");
                   printf("\nMoney Transfer \t\tB");
                   printf("\n\n*********************************************");
                   printf("\nEnter the code of your chosen mode of payment:\n");
                   scanf("%s", &mop);
                   
                      if((mop=='A')||(mop=='a')){
                      
                      printf("\nMode of Payment: Bank Deposit");}
                      
                      else
                      
                      if((mop=='B')||(mop=='b')){
                                  
                      printf("\nMode of Payment: Money Transfer");}
                      
                      
                      else
                      {
                      printf("Invalid Input!");
                      getch();
                      exit(0);}
                   
                   
                   printf("\n\nDate of Payment: ");
                   scanf("%s", &date);   
                
                
                   
           // Prompt do you wish to continue
                    printf("\nDo you wish to continue?: y/n\n");
               scanf("%s", &ans);
                
                if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
              
                  { exit(0);}
                  
                 else 
                   
                   { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
                  
           
           //Display Claim Order
          char code;
          
          printf("How to claim your order \tCode");
          printf("\n\nPick-up \t\t\tA");
          printf("\nDelivery \t\t\tB");
    
    
           //Enter DeliveryCode
          printf("\n\nEnter code here: ");
          scanf("%s", &code);
          
                      if((code=='A')||(code=='a')){
                      
                      printf("\nOrder by: Pick-up");}
                      
                      else
                      
                      if((code=='B')||(code=='b')){
                                  
                      printf("\nOrder by: Delivery");}
                      
                      
                      else
                      {
                      printf("Invalid Input!");
                      getch();
                      exit(0);}
                   
           
           // Prompt do you wish to continue
            printf("\n\nDo you wish to continue?: y/n\n");
               scanf("%s", &ans);
                
               if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
                  
                  { exit(0);}
                  
                 else 
                   
                    { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
                             
          printf("\n________________________________________________________________________________");
          printf("\n\t\t\t\tORDER VERIFICATION\n");
          printf("\n\nOrdered item:  ");
          {
          
          if (item_code==1)
          printf("Dream Pillow",item_code);
          else
          if(item_code==2)
          printf("Bolster Pillow",item_code);
          else
          if(item_code==3)
          printf("Fantasy Pillow",item_code);
          else
          if(item_code==4)
          printf("Health Pillow",item_code);
          
          }
          
          printf("\nQuantity: %d\n",quantity);
          
          printf("Total amount of purchased: %.2f\n", tprice);
          
           //Prompt 1 or 2
          
          printf("Complete name: %s\n", name);
          printf("Complete Address: %s\n", address);
          printf("Postal Code: %s\n", pcode);
          printf("Contact Number: %s\n", contact);
          printf("E-mail Address: %s\n", e_add);
          printf("Mode of Payment: %s\n",mop);
          printf("Claim your item thru: %s\n",code);
          
          // Prompt do you wish to continue
          printf("\n\nDo you wish to continue?: y/n\n");
               scanf("%s", &ans);
                
                if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
                  
                  { exit(0);}
                  
                 else 
                   
                    { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
          
    
    
           //Display Merchant Details
          printf("\n________________________________________________________________________________");
          printf("\nPlease copy the merchant's details for sending your payments  \n");
          printf("\nFor Bank Deposit: \n");
          printf("\tAccount name: Chin Go\n\tAccount number: 4444-8888-48\n\tName of bank: Banco de Oro\n");
          printf("\nFor Money Transfer: \n");
          printf("\tName: Chin Go\n\tContact No.: 888-8888\n\tAddress: Blk-88 Lot -01 Lucky Village, Pasig City\n");
          printf("\n________________________________________________________________________________");
          
          printf("\n\nDo you wish to continue?: y/n\n");
               scanf("%s", &ans);
                
                if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
                  
                  { exit(0);}
                  
                 else 
                   
                    { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
           
                  
           //Display transaction complete
          printf("\n\n\n\n\n\n\n\t\t\t    TRANSACTION COMPLETE\n");
          printf("\t\tYour order was successfully sent. Please check\n\t\t\tyour e-mail for the invoice.");
          printf("\n\n\t\t\tThank you for shopping!!!");
          printf("\n\n\n\n\n\n\n\n\n\n\nAnother transaction?: y/n\n");
          scanf("%s",&ans);
           
            if ((ans=='y')||(ans=='Y'))
               
                             
                  { system("cls"); } 
                   
                 else  
               
               if ((ans=='n')||(ans=='N'))
                  
                  { exit(0);}
                  
                 else 
                   
                    { printf("\nInvalid Input! program will now exit");
                  exit(0);} 
          
          
          
          getch();
          exit(0);
                     
          getch();
    
    
    }

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well it's got all the same problems that your other program has.
    - poor formatting
    - main too long
    - abuse of %s scanf
    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.

  3. #3
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Do you have memory issues?
    If yes, I think you should seek medical attention in the VERY near future because you are forgetting too much to function normally.

    If not, why are you NOT just using a single thread for your single topic?

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. program to close its own window
    By wizard21212 in forum C Programming
    Replies: 5
    Last Post: 04-20-2011, 11:57 PM
  2. Program has encountered a problem and needs to close
    By TrippyJing in forum C++ Programming
    Replies: 4
    Last Post: 04-27-2010, 12:17 PM
  3. Your program has encountered a problem and needs to close error
    By taka209 in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2008, 09:42 PM
  4. How to Close Parent Program using child Program?
    By beon in forum Windows Programming
    Replies: 2
    Last Post: 11-30-2007, 10:24 PM
  5. Why does DOS always close after the program completes?
    By 7smurfs in forum C++ Programming
    Replies: 9
    Last Post: 10-22-2004, 01:14 PM