By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,750 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,750 IT Pros & Developers. It's quick & easy.

switch not working

P: n/a
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);
}

Feb 21 '07 #1
Share this Question
Share on Google+
5 Replies


P: n/a
eh**********@gmail.com wrote:
>
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?
--
Ian Collins.
Feb 21 '07 #2

P: n/a
Ian Collins wrote:
eh**********@gmail.com wrote:
>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.
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

Feb 21 '07 #3

P: n/a
CBFalconer wrote:
Ian Collins wrote:
>>eh**********@gmail.com wrote:

>>>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.


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

--
Ian Collins.
Feb 21 '07 #4

P: n/a
Ian Collins <ia******@hotmail.comwrote:
scanf("%4d",&(*cust).customer_no);
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.)

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 21 '07 #5

P: n/a
On Feb 21, 7:43 pm, CBFalconer <cbfalco...@yahoo.comwrote:
Ian Collins wrote:
ehabaziz2...@gmail.com wrote:
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.

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...)
Feb 22 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.