URGENT

U

Umesh

CoffeeVendor is a program, which simulate a coffee machine. The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit
cards and debit cards. Detailed specification is as follows:
(i) Functional Requirements:
a) Accept cash input in value of 1, 2 or 5 rupee coins.
b) Accept credit card (with credit limit).
c) Accept debit card (with PIN number and balance).
d) Serve coffee with sugar and creamer for Rs.10/-.
e) Serve black coffee without sugar and cream for Rs.6/-.
f) Put correct amount of money on credit card and debit card.
(ii) Output Requirements:

a) Display the total amount of money after inputting the cash.
b) Display error message when there is no enough money, over credit
limit, balance
below zero, insert invalid cash, or input invalid
command.
c) Display receipt after each transaction.

(iii) Constraints:
a) One cup of white coffee contains one unit of coffee powder, sugar
and creamer, while one cup of black coffee only contains one unit of
coffee powder and water. For the coffee machine, there is a limit
capacity of the coffee powder, sugar and creamer. If there isn't
enough coffee powder available, the coffee machine cannot serve the
black coffee. And if there is not enough coffee powder, sugar and
creamer, the coffee machine cannot serve the white coffee. When the
coffee machine cannot fulfill the user request, the money should be
refunded to users.
b) After each transaction, user should re-enter the credit card or
debit card to perform another transaction.
c) The limit capacity, the credit card and the debit card information
will be stored in three different files, and will be read in when the
program is launched. If the initial capacity cannot serve for at least
one cup of coffee, print out an error message, if the format of credit
card and debit card files is not correct, print out error messages.
Related files are:
· ingredient.dat - Coffee, Sugar and creamer limits
· debitCard.dat - Debit card number, PIN and Balance
· creditCard.dat - Credit card number, credit limit
(iv) Environment:
a) Character mode interface.
b) Develop using C programming language.
 
C

Charlton Wilbur

U> CoffeeVendor is a program, which simulate a coffee machine.

You neglected to indicate how much you were paying and your
instructor's email address.

Charlton
 
W

Walter Roberson

Umesh said:
CoffeeVendor is a program, which simulate a coffee machine.

You did not ask a question. If the question is "Can this be
written in standard C", the answer is "Yes on hosted systems
that permit files with the given names, provided that the
'character mode interface' required is just plain-text output
without (for example) absolute location positioning to simulate
the machine operation."

The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit
cards and debit cards. Detailed specification is as follows:
(i) Functional Requirements:
a) Accept cash input in value of 1, 2 or 5 rupee coins.
b) Display error message when there is no enough money, over credit
limit, balance below zero, insert invalid cash, or input invalid
command.

Your requirements do not specify what is to happen if the user
puts in more money than the value of their transaction. There
was no requirement specified for making change, no discussion
of what should happen if the correct change could not be made,
and no file specifying the initial distribution of coins in
the machine available for making change. At the same time, the
specifications do not permit an error message for the case
of too *much* money. ("insert invalid cash" is not the same
as "exact change required".)
 
C

Carramba

Charlton Wilbur skrev:
U> CoffeeVendor is a program, which simulate a coffee machine.

You neglected to indicate how much you were paying

Just by careful or you may get paid in simulation

and your
 
P

Paul Uiterlinden

Umesh said:
CoffeeVendor is a program, which simulate a coffee machine. The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit
cards and debit cards. Detailed specification is as follows:

You're already too late!

Course Code : MCSL-017
Course Title : C and Assembly Language Programming
Assignment Number : MCA(1)/017/Assign/07
Maximum Marks : 100
Weightage : 25%
Last date of Submission : 30th April, 2007

Or did your instructor borrow the assignment from the internet?
 
K

Keith Thompson

Umesh said:
CoffeeVendor is a program, which simulate a coffee machine. [...]
b) Develop using C programming language.

Observation: You need a C program that satisfies the stated
requirements.

Observation: The rest of us do not need such a program.

Question: Logically, then, who should do the work of implementing it?

Hint: The correct answer begins with "U" and ends with "mesh".

Summary: Do your own damned homework. Or fail. It's up to you.
 
O

osmium

:

CoffeeVendor is a program, which simulate a coffee machine. The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit
cards and debit cards. Detailed specification is as follows:
(i) Functional Requirements:
a) Accept cash input in value of 1, 2 or 5 rupee coins.
b) Accept credit card (with credit limit).
c) Accept debit card (with PIN number and balance).
d) Serve coffee with sugar and creamer for Rs.10/-.
e) Serve black coffee without sugar and cream for Rs.6/-.
f) Put correct amount of money on credit card and debit card.
(ii) Output Requirements:

a) Display the total amount of money after inputting the cash.
b) Display error message when there is no enough money, over credit
limit, balance
below zero, insert invalid cash, or input invalid
command.
c) Display receipt after each transaction.

(iii) Constraints:
a) One cup of white coffee contains one unit of coffee powder, sugar
and creamer, while one cup of black coffee only contains one unit of
coffee powder and water. For the coffee machine, there is a limit
capacity of the coffee powder, sugar and creamer. If there isn't
enough coffee powder available, the coffee machine cannot serve the
black coffee. And if there is not enough coffee powder, sugar and
creamer, the coffee machine cannot serve the white coffee. When the
coffee machine cannot fulfill the user request, the money should be
refunded to users.
b) After each transaction, user should re-enter the credit card or
debit card to perform another transaction.
c) The limit capacity, the credit card and the debit card information
will be stored in three different files, and will be read in when the
program is launched. If the initial capacity cannot serve for at least
one cup of coffee, print out an error message, if the format of credit
card and debit card files is not correct, print out error messages.
Related files are:
· ingredient.dat - Coffee, Sugar and creamer limits
· debitCard.dat - Debit card number, PIN and Balance
· creditCard.dat - Credit card number, credit limit
(iv) Environment:
a) Character mode interface.
b) Develop using C programming language.

I can believe that the spec is not complete as someone has pointed out, but
the general outline seems reasonable to me. I would guess that your main
problem is fear. You are going to get off to a bad start or something.
Welcome to the club! That's what it's all about, making mistakes. As time
goes by you will be making new mistakes, which may be some small comfort.
Coffee machines are very rigid devices, there are two parts of the
transaction "give me the money" and "what do you want?" in that order.
Perhaps two menus might make sense, because, properly, "do you want cream"
should be grayed out until the money part of the deal is finished. And
graying out is not a readily available feature of a character mode C
interface. (To be strict, C doesn't *have* a character mode interface, it
is a *line* mode, you have to push Enter before anything happens.) Keep
that in mind, as you write your menu. C does not natively produce programs
that are end-user friendly.

Try to find the easiest (least scary) path through the problem. How about
giving a cup of black coffee to a customer with a credit card with enough
money in the account? And grow from there. I would expect your confidence
to grow as you work your way through this exercise. The problems are not,
in my experience in the nitty-gritty of the pieces. It is to get the pieces
to all fit together in a working whole. Plan on compiling at least 50 times.
Don't write a big piece of code and then start compiling, this is not a
course in learning how to type..

Maybe your first step is a menu that produces this display.and waits for a
line to be entered.
---------------
How do you want to pay?

a) Coins
b) Credit card
c) Debit card.

If the user presses anything other than 'b' followed by Enter, you simply
print a message "Function ____ is not implemented yet". Such a thing is
called a "stub".
 
O

osmium

osmium said:
:

CoffeeVendor is a program, which simulate a coffee machine. The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit

<snip> I see that OE is having one of its periodic fits where it doesn't add
corner brackets. This happens to others as well as me. Give the guys at us
a break, it's only major release 6
 
D

Default User

osmium said:
<snip> I see that OE is having one of its periodic fits where it
doesn't add corner brackets. This happens to others as well as me.
Give the guys at us a break, it's only major release 6

Unless you're constrained for some reason to use OE, I would recommend
switching on one of the many fine newsreaders out there that don't have
the bugs and odd design decisions.




Brian
 
J

Jack Klein

CoffeeVendor is a program, which simulate a coffee machine. The coffee
machine serves coffee with sugar and creamer for Rs.10/- and Rs.6/-
without sugar and creamer (black coffee). The coffee machine accepts
cash in value of Rs.1/-, Rs.2/- and Rs.5/- coins, as well as credit
cards and debit cards. Detailed specification is as follows:
(i) Functional Requirements:
a) Accept cash input in value of 1, 2 or 5 rupee coins.
b) Accept credit card (with credit limit).
c) Accept debit card (with PIN number and balance).
d) Serve coffee with sugar and creamer for Rs.10/-.
e) Serve black coffee without sugar and cream for Rs.6/-.
f) Put correct amount of money on credit card and debit card.
(ii) Output Requirements:

a) Display the total amount of money after inputting the cash.
b) Display error message when there is no enough money, over credit
limit, balance
below zero, insert invalid cash, or input invalid
command.
c) Display receipt after each transaction.

(iii) Constraints:
a) One cup of white coffee contains one unit of coffee powder, sugar
and creamer, while one cup of black coffee only contains one unit of
coffee powder and water. For the coffee machine, there is a limit
capacity of the coffee powder, sugar and creamer. If there isn't
enough coffee powder available, the coffee machine cannot serve the
black coffee. And if there is not enough coffee powder, sugar and
creamer, the coffee machine cannot serve the white coffee. When the
coffee machine cannot fulfill the user request, the money should be
refunded to users.
b) After each transaction, user should re-enter the credit card or
debit card to perform another transaction.
c) The limit capacity, the credit card and the debit card information
will be stored in three different files, and will be read in when the
program is launched. If the initial capacity cannot serve for at least
one cup of coffee, print out an error message, if the format of credit
card and debit card files is not correct, print out error messages.
Related files are:
· ingredient.dat - Coffee, Sugar and creamer limits
· debitCard.dat - Debit card number, PIN and Balance
· creditCard.dat - Credit card number, credit limit
(iv) Environment:
a) Character mode interface.
b) Develop using C programming language.

If you don't do your own work, you won't learn anything.

If you don't learn anything, when you finish school you will most
likely get a job refilling coffee vending machines. Real, not
simulated, coffee machines, that is.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://c-faq.com/
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.club.cc.cmu.edu/~ajo/docs/FAQ-acllc.html
 
U

Umesh

#include<stdio.h>
static int clevel, slevel, crlevel;
int check_ingredient_limit(int choice, int clevel, int slevel, int
crlevel)
{
if(choice == 1)
{
if(clevel <= 0)
{
printf("\nSorry, There is not enough coffee to provide you any
coffee");
}
else if(slevel <= 0)
{
printf("\nThere is not enough sugar to serve you white coffee");
printf("\nYou can opt for a Black Coffee");
}
else if(crlevel <=0)
{
printf("\nThere is not enough cream to serve you white coffee");
printf("\nYou can opt for a Black Coffee");
}
}
else
if(clevel <= 0)
{
printf("\nSorry, There is not enough coffee to provide you any
coffee");
}
return(1);
}
int check_coin(int coin_amount, int remaining_amount)
{
int s;
if ((remaining_amount<2) && (coin_amount>=2))
{
printf("\nInvalid Coin ,Please insert Re.1 coin only");
printf("\nTake your money back and insert a coin again");
s=0;
}
else if ((remaining_amount<5) && (coin_amount >= 5))
{
printf("\nInvalid Coin ,Please insert Re.1 or Rs.2 coins only");
printf("\nTake your money back and insert a coin again");
s=0;
}
else if((coin_amount != 5)&&(coin_amount != 2)&&(coin_amount != 1))
{
printf("\nInvalid Coin ,Please insert Re.1, Rs.2 or Rs.5 coins only");
printf("\nTake your money back and insert a coin again");
s=0;
}
else
s=1;
return(s);
}
int main()
{
FILE *fp;
int coffee_choice=0, payment_option;
int coin_amount, total_amount=0, s, remaining_amount;
int debit_no, dn, balance;
char pin[10];
int credit_no, cn, credit_limit;
printf("\n*************** Welcome to Coffee Vendor Machine
******************\n");
printf("\n\tCost of White Coffee Rs.10 \n\tCost of Black Coffee Rs.
6\n");
printf("\n What Would You Like to Have?\n\t1: White Coffee \n\t2:
Black Coffee\n");
printf("\nPlease Select either 1 or 2 and enter your choice: ");
scanf("%d",&coffee_choice);
if( (coffee_choice < 1) || (coffee_choice >2))
{
printf("\nInvalid Choice!!! Please enter 1 or 2 only\n");
printf("\nProgram Terminated. Please start again\n");
return(0);
}
if((fp=fopen("ingredient.dat","r")) == NULL)
printf("\nUnable to open the file\n");
else
{
do
{
fscanf(fp,"%d%d%d", &clevel, &slevel, &crlevel);
}while(!feof(fp));
}
check_ingredient_limit(coffee_choice, clevel, slevel, crlevel);
fclose(fp);
printf("\nEnter your Payment option \n\t1:CASH \n\t2:CREDIT CARD \n
\t3:DEBIT CARD\n");
printf("\nPlease Select 1, 2 or 3 and enter your Option: ");
scanf("%d",&payment_option);
if( (payment_option != 1) && (payment_option != 2) && (payment_option !
= 3))
{
printf("\nInvalid Option!!! Please enter 1, 2 or 3 only\n");
printf("\nProgram Terminated. Please start again\n");
return(0);
}
if(payment_option == 1)
{
if(coffee_choice == 1)
{
remaining_amount = 10;
printf("\nPlease pay Rs.10 to provide White Coffee");
}
if(coffee_choice == 2)
{
remaining_amount = 6;
printf("\nPlease pay Rs.6 to provide Black Coffee");
}
printf("\nKindly pay in terms of Rs.1, Rs.2 or Rs.5 coins only");
printf("\nPlease insert your coin");
do
{
scanf("%d",&coin_amount);
s=check_coin(coin_amount, remaining_amount);
if(s==1)
{
total_amount += coin_amount;
if ((coffee_choice == 1) && (total_amount==10))
{
printf("\nTake White Coffee\n");
s=1;
}
else if ((coffee_choice == 2) && (total_amount==6))
{
printf("\nTake Black Coffee\n");
s=1;
}
else
{
s=0;
printf("\nYou have paid only Rs. %d", total_amount);
if(coffee_choice == 1)
{
remaining_amount = 10 - total_amount;
printf("\nPlease Give Re.%d more to get White Coffee",
remaining_amount);
}
if(coffee_choice == 2)
{
remaining_amount = 6 - total_amount;
printf("\nPlease Give Re.%d more to get Black Coffee",
remaining_amount);
}
}
}
}while(s==0);
}
if(payment_option == 2)
{
printf("\n Credit Card\n");
if((fp=fopen("creditcard.dat","r")) == NULL)
printf("\nInvalid Credit Card\n");
else
do
{
fscanf(fp,"%d%d", &credit_no, &credit_limit);
}while(!feof(fp));
printf("\n Credit Card Number %d", credit_no);
printf("\n Credit Limit %d", credit_limit);
printf("\nPlease Enter your Credit Card Number: ");
scanf("%d", &cn);
printf("\nConnecting to your bank server, please wait...");
if(cn != credit_no)
{
printf("\nInvalid Credit Card");
printf("\nProgram Terminated");
printf("\nPlease restart for new transaction");
}
else
{
if((coffee_choice == 1) && (credit_limit<10))
printf("\nYour Credit Limit has crossed ");
else if ((coffee_choice == 1) && (credit_limit>=10))
printf("\nTake White Coffee\n");
if((coffee_choice == 2) && (credit_limit<6))
printf("\nYour Credit Limit has crossed ");
else if ((coffee_choice == 2) && (credit_limit>=6))
printf("\nTake Black Coffee\n");
}
fclose(fp);
}
if(payment_option == 3)
{
if((fp=fopen("debitcard.dat","r")) == NULL)
printf("\nInvalid Debit Card\n");
else
do
{
fscanf(fp,"%d%s%d", &debit_no, pin, &balance);
}while(!feof(fp));
printf("\n Debit Card Number %d", debit_no);
printf("\n PIN %s", pin);
printf("\n Balance %d", balance);
printf("\nPlease Enter your Debit Card Number: ");
scanf("%d", &dn);
printf("\nConnecting to your bank server, please wait...");
if(dn != debit_no)
{
printf("\nWrong Dedit Card");
printf("\nProgram Terminated");
printf("\nPlease restart for new transaction");
}
else
{
if((coffee_choice == 1) && (balance<10))
printf("\nYour Credit Limit has crossed ");
else if ((coffee_choice == 1) && (balance>=10))
{
printf("\nTake White Coffee");
balance = balance - 10;
}
if((coffee_choice == 2) && (balance<6))
printf("\nYour Credit Limit has crossed ");
else if ((coffee_choice == 2) && (balance>=6))
printf("\nTake Black Coffee");
}
fclose(fp);
}
return(0);
}
 
R

Richard Heathfield

Umesh said:

<200+ lines of code>

gcc says:

foo.c:3: warning: declaration of `clevel' shadows global declaration
foo.c:3: warning: declaration of `slevel' shadows global declaration
foo.c:4: warning: declaration of `crlevel' shadows global declaration
foo.c:5: warning: no previous prototype for `check_ingredient_limit'
foo.c: In function `check_ingredient_limit':
foo.c:5: warning: declaration of `crlevel' shadows global declaration
foo.c:5: warning: declaration of `slevel' shadows global declaration
foo.c:5: warning: declaration of `clevel' shadows global declaration
foo.c: At top level:
foo.c:31: warning: no previous prototype for `check_coin'
foo.c:56: warning: function declaration isn't a prototype
foo.c: In function `main':
foo.c:59: warning: `remaining_amount' might be used uninitialized in
this function
 
K

Keith Thompson

Umesh said:
#include<stdio.h>
[223 lines deleted]

And?

You just posted over 200 lines of code, but you didn't say anything
about it. That's an improvement over posting a set of requirements
without asking anything (implicitly, I suppose, asking someone to do
your homework for you), but you still need to be clear about what
you're asking for. Are you asking for help with the program? Does
it work? If it doesn't work, *how* doesn't it work?

Also, the code you posted was not indented. If you didn't use any
indentation when you wrote it, please do so; it makes it much easier
to read. If you used tab characters for indentation, try to use
spaces instead; news software sometimes eats tabs.
 
O

osmium

Umesh said:
#include<stdio.h>
static int clevel, slevel, crlevel;
int check_ingredient_limit(int choice, int clevel, int slevel, int
crlevel)

<snip much code>

Well! You are quite the typist if you did all that since yesterday. Google
often retains indentation that my own news reader doesn't get. Alas, in
this case, it is not so. No indentation on Google either.

Looks like a pretty serious attempt and probably has a lot of promise. I
think you have a pretty good grasp of the fundamentals. But there is
virtually no structure to the program, it just starts and goes on and on and
on. main() alone seems to be several hundred lines long. (Later... It
isn't that long it just *looked* that long to me.) I did peek at it a bit
and don't think it complies with the specification. In particular, this
bit:

<quote>
c) The limit capacity, the credit card and the debit card information
will be stored in three different files, and will be read in when the
program is launched.
<end quote>

I read that as saying arrays should be created and filled from the credit
and debit files. The program operates on those arrays, not the files. Are
you, by chance, only serving one customer and then going out of existence?
The first part of the assignment refers to simulating a coffee machine.
They don't build coffee machine to serve a single customer and then be
scrapped. That is, at least partially, what the menu I mentioned yesterday
was all about. My recollection is that the spec allows you to simply
abandon the files when the program terminates, I don't recall provisions
telling you to save them so you could reuse the same coffee machine in a
second run at a different time.

If I were to write a program of this complexity it would probably have ten
or twenty functions; as far as I can tell you have two. I don't think many
people will offer much in-depth help for such an unorganized attempt for
free, that is what we do for money!

If my guess is right, you serve one cup of coffee and junk the machine, you
need a substantial rewrite and rethink anyway. At the same time you are
rewriting you could break it down into several functions.

Later. I think your instructor wants a credit card file to contain records
for several customers, not just one. It is up to you to search for and find
the proper record, if one exists. And update it after serving each cup of
coffee to that customer. If he had credit card limit of 25 Rupees he can
only buy a few cups of coffee.

As far as I can tell, you pretty seriously misunderstand the assignment. Or
else I do.
 

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

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top