I am having trouble with this problem in comps 191, the problem is we have to make a menu driven program to keep inventory of sodas, heres the info given: Suppose you own a soft drink distributorship that sells coca-cola(id number 1), Pepsi (id number 2), canada dry (id number 3), and hires (id number 4) by the case. write a menu-driven program to do the following.
(E)nter inventory
(P)urchase soda
(S)old soda
(D)isplay inventory
(Q)uit
you are to read in the case inventory for each brand at the start of the week and then process all weeklly sales and purchase records for each brand.
Each transaction will consist of two data items. The first will be the brand id number(an integer). The second will be the amount purchased (a positive integer) or amount sold (a negative number). You can assume that you always have sufficient foresight to prevent depletion of your inventory for any brand. The display of your weekly inventory is to contain the brand's name.
All interaction is via keyboard input.
Please help me tonight!!!!!!!!!!!!!!!![SIZE=7][COLOR=red]
heres what I have:
#include <iostream.h>
#include <string.h>
main()
{
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25];
char string brname[25];
void menu(char x)
{switch(x)
{case 'E': case 'e': inventory();
break;
{case 'P': case 'p': purchasesoda();
break;
{case 'S': case 's': soldsoda();
break;
{case 'D': case 'd': displayinv();
break;
{case 'Q': case 'q':
break;
default: cout<<"Invalid choice.Try again."<<endl;
}
void inventory()
{ cout<<"How many of product?";
cin>>n;
for (i=1,i<=n,i++)
{ cout<<"Enter amount for brand "<<i;
cin>>brname[i];
}
void purchasesoda()
{cout<<"How many "<<brname[i]<<" "<<branid[i]<<"do you want to purchase"
<<endl;
cin>>amounpurchased[i];
}
void soldsoda()
{ cout<<"How many"<<brname[i]<<" "<<branid[i]<<"were sold?"<<endl;
i=0;
for(i=0,i>1,i++)
amountsold[i]=inventory[i]+amountpurcha[i]-i;
}
void displayinventory()
{ cout"The amount of "<<brname[i]<<" "<<branid[i]<<"in inventory is"<<"
"<<inventory[i]+amountpurcha[i]-amountsold[i]<<endl;
}
}
Please Help Homework Due Tomorrow 03/01/2005!Please Help with Menu Problem!!!!!!!!&
Page 1 of 1
10 Replies - 1924 Views - Last Post: 01 March 2005 - 12:52 AM
Replies To: Please Help Homework Due Tomorrow 03/01/2005!
#2
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 28 February 2005 - 11:43 PM
I think i need to add this at the top:
while (cin>> x)
{ cout<<"(E)nter inventory"<<endl;
cout<<"(P)urchase soda"<<endl;
cout<<"(S)old soda"<<endl;
cout<<"(D)isplay inventory"<<endl;
cout<<"(Q)uit"<<endl;
}
while (cin>> x)
{ cout<<"(E)nter inventory"<<endl;
cout<<"(P)urchase soda"<<endl;
cout<<"(S)old soda"<<endl;
cout<<"(D)isplay inventory"<<endl;
cout<<"(Q)uit"<<endl;
}
#3
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 28 February 2005 - 11:45 PM
Not sure if you need more help with the logic/functions or the menu, but just in case you need a little push in the right direction for the menu part, here is a great snippet: http://code.dreaminc...ppet.php?sid=41
If you need help with the logic, could you specify what part exactly you are hung up on and we'll try to work through it with you.
If you need help with the logic, could you specify what part exactly you are hung up on and we'll try to work through it with you.
#4
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 28 February 2005 - 11:59 PM
well basically are my function in order, are they initiated correctly, will they produce functionaly data through input.
#5
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:09 AM
The errors im getting when i compile are for implicit declaration of functions
#6
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:28 AM
well i dunno what exatly it all entails, does it have to be idiot proof? as in they could enter
"S" or "s" or " s " and have it do the same thing?
if so, maybe refer to code.dreamincode.net snippets to help with upper/lower case stuff and also eleminating spaces in strings.
i would assume your professor sold his soul to teach comp sci so he will probably pull something retarded like that. might want to make sure the input is valid, which can be tricky but those functions in the snippets should eliminate some of the work
everything looks pretty mutch in order, the only bad thing i see is again touching on data validity
while (cin>> x)
{ cout<<"(E)nter inventory"<<endl;
cout<<"(P)urchase soda"<<endl;
cout<<"(S)old soda"<<endl;
cout<<"(D)isplay inventory"<<endl;
cout<<"(Q)uit"<<endl;
}
that while (cin >> x) is basically nailing your dick to the floor, if something goes wrong with cin (like they enter to many characters or spaces).
you may want to get user input and then do something along the lines of
while (cin.bad())
{
cout << "W...T...F?!";
}
the .bad() (maybe amadeus can touch base on how sexy that is) member works wonders for making sure the user can read and not only that but can take that newly read knowledge and make it work on a 'keyboard' or something crazy like that.
and i dunno if this was you just showing the basics of the program but this might be icky...
main()
{
...stuff
}
by default (if no datatype is declared) main will return an integer, so right there would generate an error, this can be solved by setting the datatype to void main() or return 0; at the end of the function.
also this will not generate a compiler error but....
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25]; char string brname[25];
as mutch as we would like to think c++ would intiate that "int i" to 0 (or whatever you want it to be intalized to), chances are, it won't (more like -234278549024).
so like i said, this won't generate a compiler issue because the compiler assumes that it will be intiated to 0, but trusting the compiler is like spending a night with a $2 whore....it will come back to haunt you.
if you know the dimensions of the arrays, just asign them that way. or atleast intialize i to a value.
again i dunno if you were just showig the idea of the program but...
main()
{
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25];
char string brname[25];
void menu(char x)
{
....
}
defining a function within another function (local function defintion) won't work, this will generate a compiler error, obviously this can be fixed by just moving the function outside of the main() function and calling it
void menu(char x); //Declaration of menu so that main can 'see' it
main()
{
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25];
char string brname[25];
menu(7); //or whatever value that parameter needs to be
}
void menu(char x) //Definition here
{
//something exciting and confusing
}
seems like you have a lot of function definitions within other functions, bad, hopefully the compiler has already told you it doesn't like that.
if you are just writing it like that to get the general idea say it so i can look like a dick and we can get that out of the way.
so you are on the right track of making sure they entered the right data, and other than that everything looks like it should be ok.
This post has been edited by Dark_Nexus: 01 March 2005 - 12:34 AM
#7
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:30 AM
okay ive added some stuff? still not quite compiling still having syntax erros?
new file:
Here are the errors i receive:
parse erros on lines 36,39,55
#include <iostream.h>
#include <string.h>
main()
{
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25];
char brname[25];
char x;
do
{ cout<<"(E)nter inventory"<<endl;
cout<<"(P)urchase soda"<<endl;
cout<<"(S)old soda"<<endl;
cout<<"(D)isplay inventory"<<endl;
cout<<"(Q)uit"<<endl;
cin>>x;
char menu(x);
{ switch (x)
{ case 'E': case 'e': void inventory( );
break;
case 'P': case 'p': void purchasesoda( );
break;
case 'S': case 's': void soldsoda( );
break;
case 'D': case 'd': void displayinv( );
break;
case 'Q': case 'q':
break;
default: cout<<"Invalid choice.Try again."<<endl;
}}
void sinventory();
{ cout<<"How many of product?";
cin>>n;
for (i=1,i<=n,i++)
cout<<"Enter amount for brand "<<i;
cin>>brname[i];
}
void purchasesoda();
{cout<<"How many "<<brname[i]<<" "<<branid[i]<<"do you want to purchase"
<<endl;
cin>>amounpurchased[i];
}
void soldsoda()
{ cout<<"How many"<<brname[i]<<" "<<branid[i]<<"were sold?"<<endl;
i=0;
for(i=0,i>1,i++)
amountsold[i]=inventory[i]+amountpurcha[i]-i;
}
void displayinventory()
{ cout"The amount of "<<brname[i]<<" "<<branid[i]<<"in inventory is"<<"
"<<inventory[i]+amountpurcha[i]-amountsold[i]<<endl;
}
}
new file:
Here are the errors i receive:
parse erros on lines 36,39,55
#include <iostream.h>
#include <string.h>
main()
{
int i,n,amountpurch[i],amountsold[i],inventory[i],branid[25];
char brname[25];
char x;
do
{ cout<<"(E)nter inventory"<<endl;
cout<<"(P)urchase soda"<<endl;
cout<<"(S)old soda"<<endl;
cout<<"(D)isplay inventory"<<endl;
cout<<"(Q)uit"<<endl;
cin>>x;
char menu(x);
{ switch (x)
{ case 'E': case 'e': void inventory( );
break;
case 'P': case 'p': void purchasesoda( );
break;
case 'S': case 's': void soldsoda( );
break;
case 'D': case 'd': void displayinv( );
break;
case 'Q': case 'q':
break;
default: cout<<"Invalid choice.Try again."<<endl;
}}
void sinventory();
{ cout<<"How many of product?";
cin>>n;
for (i=1,i<=n,i++)
cout<<"Enter amount for brand "<<i;
cin>>brname[i];
}
void purchasesoda();
{cout<<"How many "<<brname[i]<<" "<<branid[i]<<"do you want to purchase"
<<endl;
cin>>amounpurchased[i];
}
void soldsoda()
{ cout<<"How many"<<brname[i]<<" "<<branid[i]<<"were sold?"<<endl;
i=0;
for(i=0,i>1,i++)
amountsold[i]=inventory[i]+amountpurcha[i]-i;
}
void displayinventory()
{ cout"The amount of "<<brname[i]<<" "<<branid[i]<<"in inventory is"<<"
"<<inventory[i]+amountpurcha[i]-amountsold[i]<<endl;
}
}
#8
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:30 AM
those implicit function delcaration errors are because, like i said, you have functions being defined (rather than called) within functions, if you just add/move some brackets around it will work out. just pay attention to what is inside what, and what brackets go with which.
hope i helped in time
hope i helped in time
This post has been edited by Dark_Nexus: 01 March 2005 - 12:35 AM
#9
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:46 AM
i sent you a pm with my msn/aim so we can talk on there for quicker debugging
back to the code
first thing i see is the first do loop you use, wrong syntax really, here's what it should look like, you're just missing the while() at the end
back to the code
first thing i see is the first do loop you use, wrong syntax really, here's what it should look like, you're just missing the while() at the end
do
{
...stuff
} while (run loop while this is true); <-semicolon
This post has been edited by Dark_Nexus: 01 March 2005 - 12:49 AM
#10
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:48 AM
also, still looks like you are defining all your functions within main() they have to be outside, easy way to do this is to just cut all those functions and paste them above main()
#11
Re: Please Help Homework Due Tomorrow 03/01/2005!
Posted 01 March 2005 - 12:52 AM
just posting as i read
you are using a couple of these
this won't generate a compiler error (as always) because you are saying that you want to get a single character with cin and store it to array element 'i'
so rather than getting an entire string, or more than 1 number, you get a single number/character stored to that one array element [i];
so by using that method if you enetered "hello world"
the letter 'h' of 'hello' would get stored to array element i which is probably still 0;
basically to change this just say
this will store data to the entire array as it gets it
you are using a couple of these
cin >> variable_name[i];
this won't generate a compiler error (as always) because you are saying that you want to get a single character with cin and store it to array element 'i'
so rather than getting an entire string, or more than 1 number, you get a single number/character stored to that one array element [i];
so by using that method if you enetered "hello world"
the letter 'h' of 'hello' would get stored to array element i which is probably still 0;
basically to change this just say
cin >> variable_name;
this will store data to the entire array as it gets it
This post has been edited by Dark_Nexus: 01 March 2005 - 12:55 AM
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|