>> could you please and make modification where neccessary.
What kind of modifications are you talking about ?
Do you notice any problems ? Do you have features that you need to add ?
Main Topics
Browse All Topicshello expert,
i have written a program for virtual cashier system using dev c++.
the following is the program
could you please and make modification where neccessary.
#include<stdio.h>
#include<stdlib.h>
int main (void)
{
float b,c,d,e,f,g,h,i,j,k,r,s,t,
t=0;
z=0;
char a[100];
printf("enter name of customer-");
scanf("%s",&a);
printf("enter number of items purchased by %s-",a);
scanf("%f",&b);
for (x=1;x<b;x++)
{
printf("enter the num of itmes purchased-");
scanf("%f",&c);
printf("enter the cost of items -");
scanf("%f",&d);
z=c*d;
t=t+(c*d);
printf ("the cost of items purchased= %f x %f= %f \n",c,d,z);
}
{
printf("grand total is =%f\n",t);
}
e=(t*0.2);
printf(" 20% vat charge on items purchase := %f\n",e);
f = (t+e);
printf (" total cost of all items purchase := %f\n",f);
printf("money given by %s-",a);
scanf("%f",&g);
if (g>=f)
{
h=g-f;
printf("refund (change) given to %s-%f\n",a,h);
}
else
{
printf("no change due\n\n");
}
system("pause");
}
thanks
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
hi jomfra,
the loop looks a bit weird .. if number of items is 1, its not executed at all.
if it is 2, then the loop is executed once. and you are asking in the loop again for
"number of items purchased" .. why is that?
>> float x;
>> printf("enter number of items purchased by %s-",a);
>> scanf("%f",&b);
>> for (x=1;x<b;x++)
>> {
>> printf("enter the num of itmes purchased-");
>> scanf("%f",&c);
besides you should use the "++"-increment-operator on int's, not on a float
>> float b,c,d,e,f,g,h,i,j,k,r,s,t,
it helps a lot, if you start using better names for your variables...
ike
>> is it possible you can rewrite the above program using better names for varibles etc.
well, we can help you learning and assist you .. but i won't do the work for you .. then you have to hire a programmer ;)
why not giving it a try and post here what you have changed so far .. i'm sure we can help you doing it ..
that way you will learn a lot more .. its your turn .. :)
ike
>> is it possible you can rewrite the above program using better names for varibles etc.
1) jkr made an important remark - one that you should modify.
2) ike's remark about the loops is very valid - so you should modify the loop accordingly (either use integers for amounts and loop counters, or don't use ++).
3) As ike pointed out, right now, you have variable names that don't mean anything. It makes following the code very difficult, and makes making mistakes a lot easier.
Compare this :
scanf("%f",&d);
z=c*d;
to this eg. :
scanf("%f", &item_cost);
total_item_cost = item_amount * item_cost;
The second is easier to understand what's happening.
Making these three modifications to your code will already make it a lot better. Give it a try, and post your results here, and we'll help you further if needed.
Note that this is just a summary post, with no real new information, so it doesn't deserve any points ;)
You posted the question in the C++ TA as well, but it is pure C code. Are you interested in suggestions regarding C++? Some of the problems, e. g. 'scanf', 'putting all code into one main function', would be made very differently when actively using classes, STL, cout/cin, ... But I don't want you to bother with C++ if the requirements were for C only ...
Regards, Alex
jkr, it's not REALLY a problem, is it ? The code still works just fine ;) &a and a have the same address - they just differ in type (but scanf doesn't care about that).
Plus, the author didn't ask to fix a problem - jomfra asked to check the code and to suggest improvements (see http:#19820212). Which we all gave, but then the author didn't get back to us, and we haven't really gotten to the bottom of this ... So I'm also leaning towards a delete/no refund.
Business Accounts
Answer for Membership
by: jkrPosted on 2007-09-02 at 19:18:26ID: 19818747
In
printf("enter name of customer-");
scanf("%s",&a);
the '&' for 'a' is incorrect, just make that
printf("enter name of customer-");
scanf("%s",a);
Otherwise you will pass the address of the 1st element, and that is not what you want to do.