Notices

Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Need help with nested swtich in programming project

Post Reply New Thread Subscribe Search this Thread
 
 
Thread Tools
Old 10-19-03, 12:47 PM Thread Starter   #1
amin
New Member



Join Date: Oct 2003

 
Need help with nested swtich in programming project


Hi i was wondering if sombody could help me code nested switch statments. I'am trying to write an inventory program that keeps track of the quantity of 5 brands of soda and lets the user sell or purchase the soda and updated the quantity.
the pseudocode for this is as follows:
while(action gotten is not Quit)
{
If (action indicates a sale)
make amount a negative value
switch (action)
{
carry out sale or purchase ...or
carry out inventory display... // displays inventory when user types in "d"
carry out instruction display.. // displays instructions when user types in "I"
carry out invalid display message //default label

And within the aforementioned switch statment we have to include a update function that updates the inventory to the proper brand of soda.
i.e.:
void update(int &inventory, int amount)
so how do i do this in a nestesd switch statement?
this is part of what i have so far(i can post the rest of it if this looks too vague):
Code:
while (cin>>ch>>Brand_number>>amount,ch!='Q')
	{
      if (ch==isupper('S'))
	  {
      amount= amount * (-1);
	  }
      if(ch==isupper('S'||'P'||'D'||'I'||'Q'));
	  switch (ch)
      {
		  case 'S'|| 'P':
		  
sell_purchase(amount,quantity_c,quantity_p,quantity_d,quantity_h,Brand_number);
		  break;
		  case 'D':
          cout<<"Present Inventory:" <<endl;
		  inven_display(quantity_c,quantity_p,quantity_d,quantity_h);
          break;
		  case 'I':
		  instr_display();
		  break;
	  default:
	    cout<<"The action you requested is invalid...nothing changed "<< endl;
	  }
	  cout<<"Closing inventory: " << endl;
	  inven_display(quantity_c,quantity_p,quantity_d,quantity_h);
	}
      return 0;
}
void inven_display(
			       int& quantity_c,
			       int& quantity_p,
			       int& quantity_d,
			       int& quantity_h
				   )
{
	cout<<"Coke       -- "<<quantity_c<<endl;
    cout<<"Pepsi      -- "<<quantity_p<<endl;
	cout<<"Canada Dry -- "<<quantity_d<<endl;
    cout<<"Hires      -- "<<quantity_h<<endl;
}

sell_purchase(int& amount,
			       int& quantity_c,
                   int& quantity_p,
			       int& quantity_d,
			       int& quantity_h,
			       int Brand_number)
{
   for(Brand_number=1;Brand_number<5;)
   {
       if(Brand_number==1){
		   if(amount<=quantity_c)
             quantity_c=amount+quantity_c;
		   else
			 cout<<"insuficient inventory to fill sell order,nothing changed "<<endl;
	   	   }
	   if(Brand_number==2){
           if(amount<=quantity_p)
            quantity_p=amount+quantity_p;
		   else
			 cout<<"insuficient inventory to fill sell order,nothing changed "<<endl;
	   }
       if(Brand_number==3){
           if(amount<=quantity_d)
            quantity_d=amount+quantity_d;
		   else
             cout<<"insuficient inventory to fill sell order,nothing changed "<<endl;
	   }
	   if(Brand_number==4){
	       if(amount<=quantity_c)
			  quantity_p=amount+quantity_p;
		   else
			 cout<<"insuficient inventory to fill sell order,nothing changed "<<endl;
	   }
	    cout<<"Inventory updated...."<<endl;
	    Brand_number++;
		return 0;
   }
  }
amin is offline   QUOTE Thanks
Old 10-19-03, 05:47 PM   #2
Cowboy Shane
Member



Join Date: Jan 2002
Location: Augusta, GA

10 Year Badge
 
What, exactly, are you having problems with? Do you need to know how to implement an update function, or where to put the calls to an update function? I would probably call update from within the sell or purchase routine, but you can have as many lines of code as you want after a case condition and its corresponding break statement.

I just don't quite understand what you are having trouble doing...

__________________
I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours. -- Stephen Roberts
Cowboy Shane is offline   QUOTE Thanks
Old 10-19-03, 08:50 PM Thread Starter   #3
amin
New Member



Join Date: Oct 2003

 
oh iam sorry, iam just confused about how to implement the update function within the switch.
amin is offline   QUOTE Thanks

Post Reply New Thread Subscribe


Overclockers Forums > Software > Programming Tips and Tricks
Programming Tips and Tricks
Forum Jump

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Mobile Skin
All times are GMT -5. The time now is 03:09 PM.
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
You can add these icons by updating your profile information to include your Heatware ID, Benching Profile ID or your Folding/SETI profile ID. Edit your profile!
X

Welcome to Overclockers.com

Create your username to jump into the discussion!

New members like you have made this the best community on the Internet since 1998!


(4 digit year)

Why Join Us?

  • Share experience
  • Max out your hardware
  • Best forum members anywhere
  • Customized forum experience

Already a member?