C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old December 20th, 2006, 11:26 AM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Need Beginner C++ Help

Okay I have a program due and I am not sure what it is that I need to do. I have looked at my teachers notes for hours on end and I cannot figure it out. This is what I need to do:


The program must use a loop to present the customer with the following exact menu allowing him to make one or more orders for each of the three products if he desires.

1 Books
2 Movies
3 Peanuts
4 Checkout

In this assignment program, the customer is allowed to make two or more separate orders for the same product. For example, the customer may order 3 books and 2 movies but no peanuts. Or, the customer could order 5 books, 1 pound of peanuts, and 3 movies in that order. Or, the customer could order 6 books, 3 movies, and then 2 more books. The customer may choose menu option #4 to exit the program at any time, even if he has made no purchase.




Here is my code so far. It is a little messy because I have been screwing around with it a lot. Can someone please give me some feedback as to what I am doing wrong:

int main ()
{

// **** Constants ************************************************** ******

const int PRICE_BOOKS = 9; // price of books
const double PRICE_MOVIES = 14.99; // price of movies
const double PRICE_PEANUTS = 1.80; // price per pound of peanuts
const double SHIPPING_BOOK = 1.03; // price to ship books
const double SHIPPING_MOVIE = 0.05; // price to ship movies
const double SHIPPING_PEANUTS = 0.50; // price to ship peanuts

// **** Variable Declartions *********************************************

int numBooks = 0;
int numMovies = 0;
double numPeanuts = 0.0;
double costBooks = 0;
double costMovies = 0.00;
double costPeanuts = 0.0;
double costBookShip = 0.0;
double costMovieShip = 0.0;
double costPeanutShip = 0.0;
double totalCostMovies = 0.0;
double totalCostBooks = 0.0;
double totalCostPeanuts = 0.00;
double totalCostOrder = 0.00;
int totalCostRounded = 0;
int shippingCostBooks = 0;
double shippingCostMovies = 0.00;
double shippingCostPeanuts = 0.00;
int menuChoice = 0;

cout << "1 Books" << endl;
cout << "2 Movies" << endl;
cout << "3 Peanuts "<< endl;
cout << "4 Checkout" << endl;

cout << "Enter the number of the menu choice you would like to select: " << endl;
cin >> menuChoice;


switch (menuChoice)
{
case 1:
cout << "Enter the amount of Books that you would like to buy: ";
cin >> numBooks ;

costBooks = numBooks * PRICE_BOOKS;
costBookShip = SHIPPING_BOOK * numBooks;
totalCostBooks = costBooks + costBookShip;
break;
case 2:
cout << "Enter the amount of Movies that you would like to buy: ";
cin >> numMovies ;

costMovies = numMovies * PRICE_MOVIES;
costMovieShip = SHIPPING_MOVIE * numMovies;
totalCostMovies = costMovies + costMovieShip;
break;
case 3:
cout << "Enter the amount of Peanuts that you would like to buy: ";
cin >> numPeanuts ;

costPeanuts = numPeanuts * PRICE_PEANUTS;
costPeanutShip = SHIPPING_PEANUTS * numPeanuts;
totalCostPeanuts = costPeanuts + costPeanutShip;
break;
case 4:
totalCostOrder = totalCostBooks + totalCostMovies + totalCostPeanuts ;

totalCostRounded = static_cast <int> (totalCostOrder + 0.5);

if (totalCostRounded > 200)
{
cout << "You may only spend $200 or less." << endl;
}
else
{
cout << "The total cost of the order is $" << totalCostRounded << endl;
system("PAUSE");
}
break;
default:
cout << "You failed to enter a valid menu choice";
break;
}

totalCostOrder = totalCostBooks + totalCostMovies + totalCostPeanuts ;
totalCostRounded = static_cast <int> (totalCostOrder + 0.5);

cout << "Your total order so far is $" << totalCostRounded << endl;

if (menuChoice < 4)
{
cout << "1 Books" << endl;
cout << "2 Movies" << endl;
cout << "3 Peanuts "<< endl;
cout << "4 Checkout" << endl;

cout << "Enter the number of the menu choice you would like to select: " << endl;
cin >> menuChoice;
}


return 0;

}

//end of main

Reply With Quote
  #2  
Old December 20th, 2006, 12:46 PM
Paul820 Paul820 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jan 2006
Location: United Kingdom
Posts: 428 Paul820 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 Days 7 h 55 m 4 sec
Reputation Power: 13
Where exactly is your problem?
__________________
USE CODE TAGS: Highlight the code, click on the # button.

Reply With Quote
  #3  
Old December 20th, 2006, 01:42 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by Paul820
Where exactly is your problem?


I can get the menu to run the first time, but then the box closes. I need it to i guess loop back up to the top so that the user can input another option and it needs to keep a running total of what is being bought.

Reply With Quote
  #4  
Old December 20th, 2006, 02:07 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Well, then you might want to think of putting your menu into a function like.
void menu();
and then in your main void do a while loop with player money being the pending value. while(playermoney != 0); or something like that. ; ) so it should look something like this
Code:
#includes ->

void menu();

void menu()
{
     cout<<"Menu Here";
     //Do stuff with it
}
void main()
{
   while(playermoney != 0)
     {
          menu();
     }
}

This is just an example of course and you will have to put everything pertaining to your menu into that function. But your prog looks good so far man. ; )
__________________
---Official Member Of The Itsacon Fan Club---
Give a man a fish and he will eat for a day. Teach a man to fish and he will sit in a boat all day drinking beer.

Reply With Quote
  #5  
Old December 20th, 2006, 02:31 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Thanks for the help.

What I am thinking that void menu(); will go up at the top of the program?

Then in the actual void menu (), I cout the menu that I have in my program. Do I also put the switch function in there, that states each case? Also, the void main function, from what I am getting from this that is a seperate function outside of the int main () function. Is this correct?

Reply With Quote
  #6  
Old December 20th, 2006, 02:39 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Ya, thats correct. Its another processes all together. Take a look at this link and it might clear it up. You can also achieve this without a function by just putting your menu into a while() loop. with something like playermoney being the stopper.
Function link.

Reply With Quote
  #7  
Old December 20th, 2006, 02:56 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Thanks a lot. I might be back for some more help later, but I'd like to attempt the rest of the problem by myself before I ask for more help.

Reply With Quote
  #8  
Old December 20th, 2006, 03:04 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Sure thing man. It looks like your already in a good direction. =) just keeps going...

Reply With Quote
  #9  
Old December 20th, 2006, 04:44 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Alright what did I do wrong. I added in everything I was supposed to and the menu didnt repeat after the first order was placed. I then tried to fool around with the function a little bit but it was to no avail. What did I do wrong that this isnt working:

PHP Code:
#include <iostream>
using namespace std;

void customerMenu ();

int main ()
{

    
// **** Constants **************************************************  ******

    
const int PRICE_BOOKS 9;                 // price of books
    
const double PRICE_MOVIES 14.99;      // price of movies
    
const double PRICE_PEANUTS 1.80;      // price per pound of peanuts
    
const double SHIPPING_BOOK 1.03;      // price to ship books
    
const double SHIPPING_MOVIE 0.05;     // price to ship movies
    
const double SHIPPING_PEANUTS 0.50;   // price to ship peanuts

    // **** Variable Declartions *********************************************

    
int numBooks 0;
    
int numMovies 0;
    
double numPeanuts 0.0;
    
double costBooks 0;
    
double costMovies 0.00;
    
double costPeanuts 0.0;
    
double costBookShip 0.0;
    
double costMovieShip 0.0;
    
double costPeanutShip 0.0;
    
double totalCostMovies 0.0
    
double totalCostBooks 0.0;
    
double totalCostPeanuts 0.00;
    
double totalCostOrder 0.00;
    
int totalCostRounded 0;
    
int shippingCostBooks 0;
    
double shippingCostMovies 0.00;
    
double shippingCostPeanuts 0.00;
    
int menuChoice 0;
    
    

    
void menu ();
        
cout << "1 Books" << endl;
        
cout << "2 Movies" << endl;
        
cout << "3 Peanuts "<< endl;
        
cout << "4 Checkout" << endl;

        
cout << "Enter the number of the menu choice you would like to select: " << endl;
        
cin >> menuChoice;


        switch (
menuChoice)
        {
            case 
1:
                
cout << "Enter the amount of Books that you would like to buy: ";
                
cin >> numBooks 

                
costBooks numBooks PRICE_BOOKS;
                
costBookShip SHIPPING_BOOK numBooks;
                
totalCostBooks costBooks costBookShip;
                break;
            case 
2:
                
cout << "Enter the amount of Movies that you would like to buy: ";
                
cin >> numMovies ;

                
costMovies numMovies PRICE_MOVIES;
                
costMovieShip SHIPPING_MOVIE numMovies;
                
totalCostMovies costMovies costMovieShip;
                break;
            case 
3:
                
cout << "Enter the amount of Peanuts that you would like to buy: ";
                
cin >> numPeanuts ;

                
costPeanuts numPeanuts PRICE_PEANUTS;
                
costPeanutShip SHIPPING_PEANUTS numPeanuts;
                
totalCostPeanuts costPeanuts costPeanutShip;
                break;
            case 
4:
                
totalCostOrder totalCostBooks totalCostMovies totalCostPeanuts ;

                
totalCostRounded static_cast <int> (totalCostOrder 0.5);


                if (
totalCostRounded 200)
                {
                    
cout << "You may only spend $200 or less." << endl;
                }
                else
                {
                    
cout << "The total cost of the order is $" << totalCostRounded << endl;
                    
system("PAUSE");
                }
                break;
            default:
                
cout << "You failed to enter a valid menu choice";
                break;
        } 

        
customerMenu (totalCostRounded);
    return 
0;

}
//end of main

void customerMenu ()
{
    
int a 0;
    while(
!= 0)
    {
        
menu ();
    }



Also, here are the errors that I am getting. I think it is something simple that I am not getting right.

PHP Code:
.\a4.cpp(104) : error C2660'customerMenu' : function does not take 1 arguments
.\a4.cpp(114) : error C3861'menu'identifier not found 

Reply With Quote
  #10  
Old December 21st, 2006, 12:36 AM
patmo98 patmo98 is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 83 patmo98 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 h 5 m 47 sec
Reputation Power: 13
First, try using "highlight=c++" instead of "php" for the code tag.

Up here you declared that customerMenu() takes no arguments.

Quote:
Originally Posted by PVCap99
Alright what did I do wrong.

c++ Code:
Original - c++ Code
  1.  
  2. void customerMenu ();



but down here you call customerMenu() with an argument.

Quote:
Originally Posted by PVCap99
c++ Code:
Original - c++ Code
  1.  
  2.         }
  3.  
  4.         customerMenu (totalCostRounded);
  5.     return 0;
  6.  
  7. }//end of main
  8.  



I also can't figure out what this menu function is that you are referring to. customerMenu() will also be an infinate loop because "a" is never incremented.

Quote:
Originally Posted by PVCap99
c++ Code:
Original - c++ Code
  1.  
  2. void customerMenu ()
  3. {
  4.     int a = 0;
  5.     while(a != 0)
  6.     {
  7.         menu ();
  8.     }
  9. }


Reply With Quote
  #11  
Old December 21st, 2006, 12:57 AM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Quote:
Originally Posted by patmo98
First, try using "highlight=c++" instead of "php" for the code tag.

Up here you declared that customerMenu() takes no arguments.



but down here you call customerMenu() with an argument.



I also can't figure out what this menu function is that you are referring to. customerMenu() will also be an infinate loop because "a" is never incremented.




The whole point of the last function is that when the customer is done adding 1 book to his or her shopping cart I guess you could say, they are then shown the menu again and are able to make another selection or checkout. The "a" was just put in while trying to figure out what parameters were needed to be sent back and forth. That might be completely wrong, but I think totalCostRounded is being passed into "a".

Reply With Quote
  #12  
Old December 21st, 2006, 11:11 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Well, PVcap take a look at this. Try taking out the functions all together and just try using a while loop to loop through the menu. And just a note I changed the totalcostrounded to 100 because if not the program would just close because the user never has any money to buy anything. ; )
Code:
#include <iostream> 
using namespace std; 

void customerMenu (int looper); 
void menu ();//This is were the menu should have went ; )

int main () 
{ 

    // **** Constants **************************************************    ****** 

    const int PRICE_BOOKS = 9;                 // price of books 
    const double PRICE_MOVIES = 14.99;      // price of movies 
    const double PRICE_PEANUTS = 1.80;      // price per pound of peanuts 
    const double SHIPPING_BOOK = 1.03;      // price to ship books 
    const double SHIPPING_MOVIE = 0.05;     // price to ship movies 
    const double SHIPPING_PEANUTS = 0.50;   // price to ship peanuts 

    // **** Variable Declartions ********************************************* 

    int numBooks = 0; 
    int numMovies = 0; 
    double numPeanuts = 0.0; 
    double costBooks = 0; 
    double costMovies = 0.00; 
    double costPeanuts = 0.0; 
    double costBookShip = 0.0; 
    double costMovieShip = 0.0; 
    double costPeanutShip = 0.0; 
    double totalCostMovies = 0.0;  
    double totalCostBooks = 0.0; 
    double totalCostPeanuts = 0.00; 
    double totalCostOrder = 0.00; 
    int totalCostRounded = 100; 
    int shippingCostBooks = 0; 
    double shippingCostMovies = 0.00; 
    double shippingCostPeanuts = 0.00; 
    int menuChoice = 0; 
    //Start of the menu
    while(totalCostRounded != 0 || menuChoice != 4)
    {
        cout << "1 Books" << endl; 
        cout << "2 Movies" << endl; 
        cout << "3 Peanuts "<< endl; 
        cout << "4 Checkout" << endl; 

        cout << "Enter the number of the menu choice you would like to select: " << endl; 
        cin >> menuChoice; 


        switch (menuChoice) 
        { 
            case 1: 
                cout << "Enter the amount of Books that you would like to buy: "; 
                cin >> numBooks ;  

                costBooks = numBooks * PRICE_BOOKS; 
                costBookShip = SHIPPING_BOOK * numBooks; 
                totalCostBooks = costBooks + costBookShip; 
                break; 
            case 2: 
                cout << "Enter the amount of Movies that you would like to buy: "; 
                cin >> numMovies ; 

                costMovies = numMovies * PRICE_MOVIES; 
                costMovieShip = SHIPPING_MOVIE * numMovies; 
                totalCostMovies = costMovies + costMovieShip; 
                break; 
            case 3: 
                cout << "Enter the amount of Peanuts that you would like to buy: "; 
                cin >> numPeanuts ; 

                costPeanuts = numPeanuts * PRICE_PEANUTS; 
                costPeanutShip = SHIPPING_PEANUTS * numPeanuts; 
                totalCostPeanuts = costPeanuts + costPeanutShip; 
                break; 
            case 4: 
                totalCostOrder = totalCostBooks + totalCostMovies + totalCostPeanuts ; 

                totalCostRounded = static_cast <int> (totalCostOrder + 0.5); 


                if (totalCostRounded > 200) 
                { 
                    cout << "You may only spend $200 or less." << endl; 
                } 
                else 
                { 
                    cout << "The total cost of the order is $" << totalCostRounded << endl; 
                    system("PAUSE"); 
                } 
                break; 
            default: 
                cout << "You failed to enter a valid menu choice"; 
                break; 
        }  
}
    return 0; 

} 

Compile that and test it. It worked for me. Just practice up on using functions though because that way you can reuse that menu later in a much larger game.

Reply With Quote
  #13  
Old December 21st, 2006, 11:24 AM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
Thanks a ton Garnett. The program works like I want it to, but it does not add the orders together when the loop goes through. I'm thinking that I might be wanting to use a seperate function for this, but I am not exactly sure how that would work. Im thinking that if I am ordering 1 book and then 2 more books, the second order would overwrite whatever value I had there to begin with and I would lose the initial order. Is this correct? The next part of my assignment that I have to complete is that if the customers total order of all inputs is greater than $200, it will cout that the order is invalid and not count the last item that was added.


Quote:
But do not allow the customer to make any order that would cause the total amount of purchases plus shipping to go over $200. If he attempts to place an order for an item that would cause the running total to exceed $200, present a message that tells him that he can only spend $200 or less and present him with the menu again. Do not count the last item ordered that caused the running total to go over $200. Your program must display the total amount of money due rounded to the hundredth's place (i.e. the nearest penny).


I have already started this here:

C++ Code:
Original - C++ Code
  1. if (totalCostRounded > 200)
  2.                 {
  3.                     cout << "You may only spend $200 or less." << endl;
  4.                 }
  5.                 else
  6.                 {
  7.                     cout << "The total cost of the order is $" << totalCostRounded << endl;
  8.                     system("PAUSE");
  9.                 }
  10.                 break


I'm fairly sure that I am on the right track and that the only thing I need to do now is make sure that it gets rid of the item that made it go over.

Reply With Quote
  #14  
Old December 21st, 2006, 11:44 AM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Well, first off whats the total amount of money the user is suppose to start with, if there is no predetermined amount the you can just make the total cost something like 500 or something. But if the user is only suppose to have 200$ allowance than it needs to be 200. The way you can solve that problem is a do{}while{} loop and that is do the loop while totalcostrounded does not equal 200 instead of making it an actual choice in your menu because your not actually choosing to go over your spending limit, and really the first while loop would catch that anyways so...

And yes your order does overwrite the value if you order 1 book and then try and go back and order another 2. The way you can fix that is like so. You just make it like this.

totalCostPenuts = totalCostPenut + numberPenuts + PricePenuts;

So basically you allways add the value of the totalCost to all your values so if the user try's to add more later its all gets added up ; )

Reply With Quote
  #15  
Old December 21st, 2006, 12:10 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
There is no specified amount of money that the user is allowed to start out with. The only precondition is that he can't spend more than $200 as listed above.

Also, adding totalCostPeanuts and so on to the totals was exactly what I was looking for. I'm actually not happy that I didnt think of that myself because I should know that.

The last part of the program is:

Quote:
The program must give the customer free shipping if the total amount of purchases (not counting shipping) exceeds $100.


This is what I have going for that right now, although I think it needs to be tied into the above part.
C++ Code:
Original - C++ Code
  1.  
  2. totalOrder = costBooks + costMovies + costPeanuts;
  3.  
  4.                 if (totalOrder > 100)
  5.                 {
  6.                     totalOrder = totalCostOrder;
  7.                     totalCostRounded = static_cast <int> (totalCostOrder + 0.5);
  8.                     if (totalCostRounded > 200)
  9.                     {
  10.                         cout << "You may only spend $200 or less." << endl;
  11.                     }
  12.                     else
  13.                     {
  14.                         cout << "The total cost of the order is $" << totalCostRounded << endl;
  15.                         system("PAUSE");
  16.                     }
  17.                 }
  18.                 else
  19.                 {
  20.                     totalCostOrder = totalCostBooks + totalCostMovies + totalCostPeanuts ;
  21.                     totalCostRounded = static_cast <int> (totalCostOrder + 0.5);
  22.                     if (totalCostRounded > 200)
  23.                     {
  24.                         cout << "You may only spend $200 or less." << endl;
  25.                     }
  26.                     else
  27.                     {
  28.                         cout << "The total cost of the order is $" << totalCostRounded << endl;
  29.                         system("PAUSE");
  30.                     }
  31.                 }
  32.                 break



I think I've got the basic part down, although I did not add the do () while () loop that you mentioned earlier.

Reply With Quote
  #16  
Old December 21st, 2006, 12:21 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Ya I think that you have to add one variable and because I changed the totalCost to 500 and that is incorrect to what your trying to do. You prolly need to add a userCashAllowance or something along those lines and make it like 1,000.00$ or so and then use that for your first while loop then you need to make the second loop the totalCost. Ill show you in a minute what Im talking about. Plus keep in mind that when you go over the 200$ amount the numbers are still being stored so you still actually make the transaction. So, you also might want to make a temp value for the total cost so that you can check that and then if under 200 then do the actual addition there. Hopefully I didn't lose you with all that jargan. I will show you an example in a sec.

Reply With Quote
  #17  
Old December 21st, 2006, 12:28 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
You did lose me a little bit but I kind of understand. I'll wait for the example.

Also, while studying for my test later today I had an idea. I know that i'm already past this part but if I took the break; out of all of the case statements except for the last case, would that make it so that it would continue to show the menu? Would that be easier? Im thinking that taking the break; out of each of the cases except the fourth one will allow it to continue and then close when the user wants to check out. Is this correct?

Reply With Quote
  #18  
Old December 21st, 2006, 12:51 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
not necessarily. You want break; statements for each case and continue; when you want it to skip the loop which I dont think applies in this case. My example is taking a little longer because the program runs fine until the user enters a value greater than 200$ because your using the original values to store the amounts when the user goes over it still holds that amount and throws the whole thing off.

Reply With Quote
  #19  
Old December 21st, 2006, 12:58 PM
PVCap99 PVCap99 is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Dec 2006
Posts: 10 PVCap99 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 19 m 10 sec
Reputation Power: 0
This might not be possible but would it be possible to do something like:

C++ Code:
Original - C++ Code
  1. if (totalCostRounded > 200)
  2.                     {
  3.                         totalCostOrder = totalCostOrder - lastPurchase;  // last purchase is just a placeholder
  4.                         cout << "You may only spend $200 or less." << endl;
  5.                     }
  6.                     else
  7.                     {
  8.                         cout << "The total cost of the order is $" << totalCostRounded << endl;
  9.                         system("PAUSE");
  10.                     } 

Reply With Quote
  #20  
Old December 21st, 2006, 01:45 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
I suppose but you would have to change your code a little to allow for that. But that would probably be the easiest way to do it. Good idea.

Im heading out for lunch man, ill be back in a few.

Last edited by Geo.Garnett : December 21st, 2006 at 01:57 PM.

Reply With Quote
  #21  
Old December 21st, 2006, 04:47 PM
Geo.Garnett's Avatar
Geo.Garnett Geo.Garnett is offline
Registered Loser
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Location: Retardation Nation...
Posts: 347 Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level)Geo.Garnett User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 Days 3 h 13 m 45 sec
Reputation Power: 14
Send a message via AIM to Geo.Garnett
Well man, I finished a little example and this might not help you now but I wrote up your program using functions and what not. It makes the menu and loops until the user is broke or he exits and also if he purchases more than 100$ he gets free shipping and all that. You could through some system("CLS"); in there to clear the screen and make it a little better. But here it is.

Code:
#include <cstdlib>
#include <iostream>
//Price of books
#define BOOKS  9
#define MOVIES 14.99
#define PEANUTS 1.80
//Shipping prices
#define SBOOKS 1.03
#define SMOVIES 0.05
#define SPEANUTS 0.50
 
using namespace std; 

//Functions
void display(); //Not necessary just for glamour lol
void movie(int NumberMovies);
void book(int NumberBooks);
void peanuts(int NumberNuts);
void checkout();
void calcShipping();

//Global Variables -> I used these so you can add them wherever
double totalCostOrdered = 0.00;
double totalCostShipping = 0;
double totalUserMoney   = 1000; //Max amount of money
double bookCount = 0, movieCount = 0, nutCount = 0; //Used for shipping later
//Function declarations
void movie(int NumberMovies)
{
     
     double cost = 0.00;
     cost = NumberMovies * MOVIES;
     if(cost > 200)
     {
             cout<<"Order too large! \n";
             }
             else
             {
                 movieCount = movieCount + NumberMovies;
                 totalCostOrdered += cost;
                 }
             
     }
void book(int NumberBooks)
{
     
     double cost = 0.00;
     cost = NumberBooks * BOOKS;
     if(cost > 200)
     {
             cout<<"Order is too large! \n";
             }
             else
             {
                 bookCount = bookCount + NumberBooks;
                 totalCostOrdered += cost;
                 }
     }
void peanuts(int NumberNuts)
{
     
     double cost = 0.00;
     cost = NumberNuts * PEANUTS;
     if(cost > 200)
     {
             cout<<"Order is too large! \n";
             }
             else
             {
                 nutCount = nutCount + NumberNuts;
                 totalCostOrdered += cost;
                 }
     }
void checkout()
{
     
     cout<<"Order List: \n"
         <<"Books     : "<<bookCount<<endl
         <<"Movies    : "<<movieCount<<endl
         <<"Peanuts   : "<<nutCount<<endl
         <<"--------------------\n"
         <<"Balance   : "<<totalCostOrdered<<endl;
         }
void calcShipping()
{
     totalCostShipping = (bookCount * SBOOKS) + (movieCount * SMOVIES) + (nutCount * SPEANUTS);
     if(totalCostOrdered < 100)
     {
                         totalCostOrdered = totalCostOrdered + totalCostShipping;
                         }
                         else if(totalCostOrdered > 100)
                         {
                             cout<<"You qualified for our free shipping discount\n";
                             cout<<"You saved : "<<totalCostShipping<<endl;
                             }
                             }
void display()
{
     cout<<"               Welcome to PVcapp theatre\n"
         <<"Our special today is free shipping on purchases over 100$\n"
         <<"Order as much as you like then check out when your finished.\n"
         <<"------------------------------------------------------------\n";
         system("PAUSE");
         }
int main () 
{
    display(); //Sends user to display void
    
    int finish = 0;
    while(totalUserMoney != 0 && finish != 4) //loops until total money is gone or finish
    {
    int menuChoice = 0;
    int numMovies = 0;
    int numBooks = 0;
    int numNuts = 0;
    //Start of menu
    cout << "1 Books" << endl; 
    cout << "2 Movies" << endl; 
    cout << "3 Peanuts "<< endl; 
    cout << "4 Checkout" << endl;
    cout << "-------------"<<endl;
    cout << "Choose a number: ";
    cin >> menuChoice;
    switch(menuChoice)
    {
                      case 1:
                           cout<<"Amount to purchase : ";
                           cin >> numBooks;
                           book(numBooks); //sends number of books to book() void
                           break;
                      case 2:
                           cout<<"Amount to purchase : ";
                           cin >> numMovies;
                           movie(numMovies); //sends number of movies to movie() void
                           break;
                      case 3:
                           cout<<"Amount to purchase : ";
                           cin >> numNuts;
                           peanuts(numNuts); //sends number of nuts to peanuts() void                           

                          break;
                      case 4:
                           system("CLS"); //Clears the screen
                           cout<<"Are you sure your ready to check out? \n";
                           cout <<"1: Yes\n";
                           cout <<"2: No\n";
                           cin >> finish;
                           //Determines if it should quit or not
                           if(finish == 1)
                           {
                                     calcShipping(); //Calculates if user gets free shipping
                                     checkout(); //Displays totals and stuff                         
                                     finish = 4;
                                     }
                           else if(finish == 2)
                           {
                                finish = 0;
                                }
                           break;
                      default: 
                           cout << "You failed to enter a valid menu choice"; 
                           break;
                           }
                           }
    cin.get(); //Used to clear the keyboard buffer.
    cout<<"Press enter to finalize your purchase\n";
    cin.get();
    return 0; 

} //end of main  

But there ya go =) the only thing it doesn't do is send the user to the calcShipping void and the checkout void if the user over spends his limit. I figured this would be enough to show you another way to do it.

Last edited by Geo.Garnett : December 21st, 2006 at 05:08 PM.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Need Beginner C++ Help


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap