473,413 Members | 1,856 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

switch not working

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
5 1903
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: clueless_google | last post by:
hello. i've been beating my head against a wall over this for too long. setting the variables 'z' or 'y' to differing numbers, the following 'if/else' code snippet works fine; however, the ...
11
by: hasadh | last post by:
Hi, is the assemly code for if..else and switch statements similar. I would like to know if switch also uses value comparison for each case internally or does it jump to the case directly at...
2
by: Cathleen C via DotNetMonster.com | last post by:
I'm a semi-beginner with c# and am having a problem effectively implementing a switch statement. I've created an asp.net app that runs a report depending on which item was selected from a drop...
19
by: rdavis7408 | last post by:
Hello, I have four textboxes that the user enters the price per gallon paid at the pump, the mileage per gallon and I would like to then calculate the cost per gallon and use a switch statement to...
5
by: _DS | last post by:
I'm currently using a switch with about 50 case statements in a stretch of code that's parsing XML attributes. Each case is a string. I'm told that switch statements will actually use hash tables...
13
by: Fei Liu | last post by:
Hi Group, I've got a problem I couldn't find a good solution. I am working with scientific data files in netCDF format. One of the properties of netCDF data is that the actual type of data is only...
22
by: Technoid | last post by:
Is it possible to have a conditional if structure nested inside a conditional switch structure? switch(freq) { case 1: CASENAME if (variable==1) { do some code }
9
by: PhreakRox | last post by:
The ToClose switch in this program is not working as expected, it allways returns a null value, if anyone knows a way to fix up the code, or can suggest a better method of doing so, your help would...
9
by: mantrid | last post by:
hello In the function below radtext is an array of 3 radio buttons with values set to 1, 2 and 3. but variables starty and finishy are not returned. ...
7
by: Rohit | last post by:
Hi, I am working on a switch module which after reading voltage through a port pin and caterogizing it into three ranges(open,low or high), passes this range to a function switch_status() with...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.