switch not working

E

ehabaziz2001

Please switch in that program not working .

#include <stdio.h>
/*TV Rental Bills -Version15-using structures*/


void customer_input(struct customer_record *);
void print_bill(struct customer_record *,int);

struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
float tv_type_value;
float tv_bill;
};


main ()
{
struct customer_record customer;
float rent_per_week;
float week_rental;

char another_bill;
int i=0;
do {
i++;
//system("cls");
printf("\n Csutomer data No %d :",i);
printf("\n ========================");
customer_input(&customer);
print_bill(&customer,i);
printf("\nIs there a bill to be processed (y or n)");
scanf("\n");
scanf("%c",&another_bill);
} while (another_bill=='y');
return 0;
}

void customer_input(struct customer_record *cust)
/*----------------------------------------------*/
{
printf("\nEnter customer number :");
scanf("%4d",&(*cust).customer_no);
printf("\nEnter number of weeks rent due :");
scanf("%2d",&(*cust).no_of_weeks);
printf("Enter type of rental -c (3.60) for colors TV");
printf("\n -b (1.75) for black and white TV");
printf("\n -v (1.50) for video");
printf("\n -o (Not handle) for other : ");
scanf("\n");
scanf("%c",&(*cust).tv_type);
switch ((*cust).tv_type)
{
case 'c':
(*cust).tv_type_value=3.60;
case 'b':
(*cust).tv_type_value=1.75;
case 'v':
(*cust).tv_type_value=1.50;
default :
printf("\n Program does not handle this type of rental\n");
}
printf("\n Number of weeks rent due : %-2d",
(*cust).no_of_weeks);
printf("\n Type of rental : %-c ",(*cust).tv_type);
printf("\n Value for that type : %.2f\n",
(*cust).tv_type_value);


(*cust).tv_bill=((*cust).no_of_weeks)*((*cust).tv_type_value);
}


void print_bill(struct customer_record *cust,int k)
/*------------------------------------------------*/
{
printf("\n BILL No for Customer %d :",k);
printf("\n ========================");
printf("\n Customer number : %-4d",
(*cust).customer_no);
printf("\n Number of weeks rent due : %-2d",
(*cust).no_of_weeks);
printf("\n Type of rental : %-c ",(*cust).tv_type);
printf("\n Value for that type : %.2f\n",
(*cust).tv_type_value);
printf("\n Value of bill : %.2f\n",
(*cust).tv_bill);
}
 
I

Ian Collins

void customer_input(struct customer_record *);
void print_bill(struct customer_record *,int);
Didn't you get a warning with the above? They should come after
customer_record is defined.
struct customer_record
{
int customer_no;
int no_of_weeks;
char tv_type;
float tv_type_value;
float tv_bill;
};


main ()

main returns int.

int main(void)
scanf("%4d",&(*cust).customer_no);

Why this bizarre syntax rather than cust->customer_no?

switch ((*cust).tv_type)
{
case 'c':
(*cust).tv_type_value=3.60;
case 'b':
(*cust).tv_type_value=1.75;

Where's the break?
 
C

CBFalconer

Ian said:
Didn't you get a warning with the above? They should come after
customer_record is defined.

Why should he? The parameters are pointers to structures, and the
system already knows how big they are.

--
<http://www.cs.auckland.ac.nz/~pgut001/pubs/vista_cost.txt>
<http://www.securityfocus.com/columnists/423>

"A man who is right every time is not likely to do very much."
-- Francis Crick, co-discover of DNA
"There is nothing more amazing than stupidity in action."
-- Thomas Matthews
 
I

Ian Collins

CBFalconer said:
Why should he? The parameters are pointers to structures, and the
system already knows how big they are.
Both the compilers I uses agree with me:

gcc -Wall -ansi -pedantic x.c
x.c:6: warning: "struct customer_record" declared inside parameter list
x.c:6: warning: its scope is only this definition or declaration, which
is probably not what you want

cc x.c
"x.c", line 6: warning: dubious tag declaration: struct customer_record

cc then goes on to report:

"x.c", line 41: identifier with dubious declaration redeclared:
customer_input,
previous: "x.c", line 6
 
C

Christopher Benson-Manica

Why this bizarre syntax rather than cust->customer_no?

ITYM

&cust->customer_no

(That may be exactly what you had in mind, but it wasn't clear.)
 
O

Old Wolf

Why should he? The parameters are pointers to structures, and the
system already knows how big they are.

The above code declares 'struct customer_record' with
prototype-scope. Any subsequent file-scope definition
of 'struct customer_record' will be a different type
that is incompatible with the type in the prototype,
so it isn't possible to actually call the function.

(Don't ask me whose idea it was to add prototype scope
to the C standard...)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top