Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Nov 19th, 2005, 7:32 PM   #1
hamacacolgante
Newbie
 
Join Date: Nov 2005
Posts: 1
Rep Power: 0 hamacacolgante is on a distinguished road
Cool HELP please!!!

I've been trying to get the errors of my program corrected for one week, but everytime I correct something I screw up something else. Could anyone help me clear the errors?


#include <stdio.h>
#include <string.h>



int order, paymet, ordnum=1, wrngpay; 		                  
int sweater[30], t_shirt[30], shrt[30], slack[30]; 
float swtot, tshtot, shrtot, slatot;	 	                     
float total[30];
int validate_id(void);
int i, cost_id[30];
float calculate_order(int, int[], int[], int[], int[]);
char pay_method;
void print_report(int, int[], int[], int[], int[], int[], float[], char[]);

main() {

printf( "  \n Welcome to C Fashion! \n " );

for(i =0;i<30; ++i)
 do{
  validate_id();
   for(; validate_id() != -1; )
    printf("\n Welcome, Costumer # %d \n", cost_id);

     printf("\n\n\tProduct\t\tCost per Box\n");
     printf("\n\t Sweaters \t$150\n");
     printf("\n\t T-Shirts \t$100\n");
     printf("\n\t Shorts \t$120\n");
     printf("\n\t Slacks \t$200\n");
     
     printf( " \n Welcome, Costumer # %d \n" , cost_id );
      printf( "\n Please enter the number of sweaters you would like to order: " ) ;
      scanf( "%d", &sweater[i] );
       printf( " You have ordered %d sweaters. \n" , sweater);
      printf( "\n Please enter the number of t-shirts you would like to order: " );
      scanf( "%d", &t_shirt[i] );
       printf( " You have ordered %d t-shirts. \n" , t_shirt );  
      printf( "\n Please enter the number of shorts you would like to order: " ) ;
      scanf( "%d", &shrt[i] );
       printf( " You have ordered %d shorts. \n" , shrt );
      printf( "\n Please enter the number of slacks you would like to order: " ) ;
      scanf( "%d", &slack[i] );
       printf( " You have ordered %d slacks. \n \n" , slack );  
   

     
     if ( sweater || t_shirt || shrt || slack ) {                                        
      order = 1;
      }
      else order = 0;
      if (order)
      {
        do {
          printf("\n Select one of the following methods of payment\n");
          printf("\n1\tCheck or money order\n2\tBank Transfer\n3\tCredit Card");
          printf("\nEnter your selection: ");
          scanf("%d", &paymet);
          switch (paymet) {
            case 1: 
              wrngpay = 0;
              pay_method[i]="Check or money order";
              break;
            case 2:
              wrngpay = 0;
              pay_method[i]="Bank Transfer";
              break;
            case 3:                                                         
              wrngpay = 0;
              pay_method[i]="Credit Card";
              break;
            default: 
              wrngpay = 1;
              printf("\n This is not a valid option");
          }
        } while (wrngpay);

        printf("\nCustomer: #%d\n\n", cost_id);

        swtot = sweater * 150 ;                                                             
        tshtot = t_shirt * 100 ;
        shrtot = shrt * 120 ;
        slatot = slack * 200 ;

        printf("%20s%10s%10s\n", "Product", "Boxes", "Cost");                                
        if (sweater) printf("%20s%10d%10.2f\n", "Sweaters", sweater, swtot);
        if (t_shirt) printf("%20s%10d%10.2f\n", "T-shirts", t_shirt, tshtot);
        if (shrt) printf("%20s%10d%10.2f\n", "Shorts", shrt, shrtot);
        if (slack) printf("%20s%10d%10.2f\n", "Slacks", slack, slatot);

        printf("\n The for total for your order is: $ %.2f\n", calculate_order(i, sweater, t_shirt, shrt, slack);        
        printf("\n\n \t\tMethod of Payment: %s\n", pay_method[i] );  

       printf("\n\n \t\tEnd of order #%d \n\n", ordnum);                                         
       ordnum++ ;       
     }
     else printf( "\n\n \t No items ordered!!! \n\n" );

     
  printf("\n\n\t\t Thank you for using C Fashion!!!");
 } while(i<30);

print_report(i, cost_id, sweater, t_shirt, shrt, slack, total, pay_method);


  return 0;
}
/*-------------------------------------------------------------------------------------------------------*/

/* Function 1 */
int validate_id()
{   

 
   do{   
    printf("\n Please enter your costumer identification number or \"-1\" to exit. \n");
    scanf("%d", cost_id);

   if (cost_id >= 1 && cost_id <= 100) {       
    printf("You entered %d\n", cost_id);
    return (cost_id);
    }
 
 
   else if (cost_id == -1) 
    return (-1);
   
   else {printf("Invalid costumer identification number");}

   } while (cost_id > -1 && cost_id > 100 );
}


/* Function 2 */

float calculate_order(int 30, int a[], int b[], int c[], int d[])
{
total[i]={0};
 total[i] = total[i] + (150 * a[i]) + (100 * b[i]) + (120 * c[i]) + (200 * d[i]) ; 
   return total[i];
}

/* Function 3 */

void print_report(int i, int cost_id[], int sweater[], int t_shirt[], int shrt[], int slack[], float total[], char pay_method[])
{
printf("%20s%20s%20s%20s%20s%20s%20s\n", "customer id", "sweaters", "t-shirts", "shorts", "slacks", "total($)", "form of payment");
for(i=0; i < 30; i++) 
printf("%20d%20d%20d%20d%20d%20.2f%20s\n", cost_id[i], sweater[i], t_shirt[i], shrt[i], slack[i], total[i], pay_method[i]);
}

/* End of Program */

All help is appreciated.
hamacacolgante is offline   Reply With Quote
Old Nov 19th, 2005, 7:56 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Please read a "how to ask a question" thread. You have told us nothing helpful, only that you have some errors and are frustrated. That describes most questioners. Describe what your program is to do (rather than make us inspect closely, and guess), how it is failing to meet your expectations, what compiler errors or linker errors you are getting, even what compiler, OS, and platform you are using. In other words, help us help you in a sensible and, hopefully, more productive way. You will find the "How to post..." thread and the forum's FAQ/rules at the very top of the postings.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 19th, 2005, 8:02 PM   #3
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5 grumpy is on a distinguished road
As Dawei said, you really need to do some work on asking a question in a way that makes it more likely that people can answer, or are willing to answer.

On a quick skim, your compiler will be complaining bitterly about your code. And I am not inclined to do more than a quick skim unless you put in more effort to understanding what is going wrong for yourself.

As a rough rule, the best way to handle things when a compiler chokes is to fix the cause of the first error (or warning) first. The reason for this is that early problems can confuse the compiler when it gets to subsequent code. In other words: don't try to start at the bottom of the list of errors from the compiler and work backwards.

A couple of quick comments on specific problems in your code follow;
1) The test;
if ( sweater || t_shirt || shrt || slack ) {                                        
      order = 1;
      }
will always give a true result as the variables are arrays. Equivalence of pointers and arrays guarantees this. Most compilers will give some warning. In any event, I doubt this test is doing what you want (although I can't work out what you are trying to do). Later tests of the form
if (sweater) ...
have the same issue.

2) Having declared pay_method as a single char (i.e. a single byte), the assignment
pay_method[i] = "A string";
is guaranteed to choke your compiler. You probably intend something like;
char pay_method[some_suitable_length];
/*  and later */
strcpy(pay_method, "A string");
grumpy is offline   Reply With Quote
Old Nov 20th, 2005, 12:51 AM   #4
bl00dninja
Programming Guru
 
bl00dninja's Avatar
 
Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5 bl00dninja is on a distinguished road
try this:

give the specific errors you're getting...

use these guys here: "/*" and "*/" a little more often.
__________________
i put on my robe and wizard hat...

Have you ever heard of Plato, Aristotle, Socrates?...Morons.
bl00dninja is offline   Reply With Quote
Old Nov 20th, 2005, 12:11 PM   #5
linuxpimp20
Hobbyist Programmer
 
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4 linuxpimp20 is on a distinguished road
Quote:
Originally Posted by bl00dninja
try this:

give the specific errors you're getting...

use these guys here: "/*" and "*/" a little more often.
these are the errors i get when trying to compile it. As of right now im not ambitious enough to try to solve any of them. lol.

 gcc -ansi -O2 -Wall -pedantic -o sweater sweater.c sweater.c:16: warning: return type defaults to `int'
sweater.c: In function `main':
sweater.c:24: warning: int format, pointer arg (arg 2)
sweater.c:32: warning: int format, pointer arg (arg 2)
sweater.c:35: warning: int format, pointer arg (arg 2)
sweater.c:38: warning: int format, pointer arg (arg 2)
sweater.c:41: warning: int format, pointer arg (arg 2)
sweater.c:44: warning: int format, pointer arg (arg 2)
sweater.c:62: error: subscripted value is neither array nor pointer
sweater.c:66: error: subscripted value is neither array nor pointer
sweater.c:70: error: subscripted value is neither array nor pointer
sweater.c:78: warning: int format, pointer arg (arg 2)
sweater.c:80: error: invalid operands to binary *
sweater.c:81: error: invalid operands to binary *
sweater.c:82: error: invalid operands to binary *
sweater.c:83: error: invalid operands to binary *
sweater.c:86: warning: int format, pointer arg (arg 3)
sweater.c:87: warning: int format, pointer arg (arg 3)
sweater.c:88: warning: int format, pointer arg (arg 3)
sweater.c:89: warning: int format, pointer arg (arg 3)
sweater.c:91: error: syntax error before ';' token
sweater.c:92: error: subscripted value is neither array nor pointer
sweater.c:103: warning: passing arg 8 of `print_report' makes pointer from integer without a cast
sweater.c: In function `validate_id':
sweater.c:119: warning: comparison between pointer and integer
sweater.c:119: warning: comparison between pointer and integer
sweater.c:120: warning: int format, pointer arg (arg 2)
sweater.c:121: warning: return makes integer from pointer without a cast
sweater.c:125: warning: comparison between pointer and integer
sweater.c:130: warning: comparison between pointer and integer
sweater.c:130: warning: comparison between pointer and integer
sweater.c: At top level:
sweater.c:136: error: syntax error before numeric constant
sweater.c: In function `calculate_order':
sweater.c:137: error: number of arguments doesn't match prototype
sweater.c:12: error: prototype declaration
sweater.c:138: error: syntax error before '{' token
sweater.c: At top level:
sweater.c:138: warning: ISO C does not allow extra `;' outside of a function
sweater.c:139: warning: type defaults to `int' in declaration of `total'
sweater.c:139: warning: ISO C90 forbids variable-size array `total'
sweater.c:139: error: variable-size type declared outside of any function
sweater.c:139: error: variable-sized object may not be initialized
sweater.c:139: error: conflicting types for 'total'
sweater.c:9: error: previous declaration of 'total' was here
sweater.c:139: error: `a' undeclared here (not in a function)
sweater.c:139: error: `b' undeclared here (not in a function)
sweater.c:139: error: `c' undeclared here (not in a function)
sweater.c:139: error: `d' undeclared here (not in a function)
sweater.c:139: error: ISO C forbids data definition with no type or storage class
sweater.c:140: error: syntax error before "return"
sweater.c: In function `print_report':
sweater.c:149: warning: format argument is not a pointer (arg 8)
linuxpimp20 is offline   Reply With Quote
Old Nov 20th, 2005, 12:26 PM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Did you read Grumpy's response at all? If you don't quite understand what he pointed out, post back; mention what, specifically, bumfoozled you. Do read the "How to Post..." thread; there be good tips there. When it comes to debugging, information is key. When it comes to getting help, information is key. Take a deep breath and realize that we are looking at your problem through YOUR eyes and intellect, not through a crystal ball.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Nov 21st, 2005, 3:17 AM   #7
The Dark
Expert Programmer
 
Join Date: Jun 2005
Posts: 816
Rep Power: 4 The Dark is on a distinguished road
Dawei: linuxpimp20 != hamacacolgante
The Dark is offline   Reply With Quote
Old Nov 21st, 2005, 5:36 AM   #8
grumpy
Programming Guru
 
grumpy's Avatar
 
Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,198
Rep Power: 5 grumpy is on a distinguished road
I'll take pity. The first warning is with this line;
printf("\n Welcome, Costumer # %d \n", cost_id);
gcc is actually a good compiler; compilers are NOT actually required to help you with this sort of error. The reason for the warning is that %d suggests the argument after the format string is an int. But cost_id is an array of 30 int's, which the compiler will pass to printf() as a pointer. Presumably the intent is to print one of the elements of the cost_id array.

There will be a logic behind each and every warning or error emitted by any compiler. I've given one example to get you started. Now you just need to go through every warning, work out what the offending code is doing wrong. Then, assuming you understand what you are trying to do with each offending line of code, you can work out how you should rewrite it.

One thing to remember is that a compiler cannot read your mind. It interprets the code quite literally.
grumpy is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:59 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC