![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Nov 2005
Posts: 1
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#3 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,209
Rep Power: 5
![]() |
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;
}if (sweater) ... 2) Having declared pay_method as a single char (i.e. a single byte), the assignment pay_method[i] = "A string"; char pay_method[some_suitable_length]; /* and later */ strcpy(pay_method, "A string"); |
|
|
|
|
|
#4 |
|
Programming Guru
![]() Join Date: Oct 2004
Location: namespace std
Posts: 1,246
Rep Power: 5
![]() |
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. |
|
|
|
|
|
#5 | |
|
Hobbyist Programmer
Join Date: May 2005
Location: ma
Posts: 130
Rep Power: 4
![]() |
Quote:
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) |
|
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#7 |
|
Expert Programmer
Join Date: Jun 2005
Posts: 825
Rep Power: 4
![]() |
Dawei: linuxpimp20 != hamacacolgante
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() Join Date: Jun 2005
Location: Adelaide, South Australia
Posts: 1,209
Rep Power: 5
![]() |
I'll take pity. The first warning is with this line;
printf("\n Welcome, Costumer # %d \n", cost_id);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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|