Programming Help

Collapse

Ad

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Capthemfoos
    Honorary DSA

    Programming Help

    Hey guys. I am taking a C++ programming course and I don't know what to do. I am using MS Visual C++ Express edition 2005 as required by the course. Here are the project instructions:

    Graded Project 1: Grocery Store
    For this project, create a grocery store system. Users of the system can choose how many items
    they want to buy and then are told how much they owe. Users will have the option of buying
    apples and oranges. Here are some parameters that your program should include:
    · Program should ask users how many apples and oranges they want to buy.
    · Apples cost $1.00 and Oranges cost $1.50.
    · Today’s Special! Apples are 2 for 1. Buy one get one free! (1 apple = $1.00, 2 apples =
    $1.00, 3 apples = $2.00, 4 apples = $2.00, etc.)
    · Another Special! How ever many oranges you buy will give you the same number of
    percentage off your total bill. (If you buy 10 oranges you get 10% off your total bill. ) (For
    now, ask the user to enter a number between 1 and 100. If they don’t the numbers will
    not make sense. Later we will learn how to capture user input errors.
    · If you have bought 2 apples = $1.00 and 10 oranges = $15.00 your total bill would be
    $16.00. But you get 10% off! (use percentage/100*amount = discount amount) 10% of
    $16.00 = (10/100) * 16.00 = $1.60 discount. Total bill = $16.00 - $1.60 = $14.40
    · Your program should tell the user how much they owe.
    Other things to keep in mind:
    · Use one function to calculate the price of the apples and another function to calculate the
    price of the oranges.
    · If you have programmed before, do not use the If statement. You should be able to
    program this project without using the If statement (We’ll learn about the If statement in
    the next workshop)
    When you are finished:
    · Submit the .cpp source file, .exe file and code file to your instructor in a zipped folder.
    · Put your name in a comment at the top of the file, followed by the name of the program.
    Evaluation Criteria
    Your project will be evaluated using the following criteria:
    1. The program compiles/builds successfully, runs normally (no runtime errors or
    unnecessary delays), and exits normally.
    2. The program asks how many apples you want and receives keyboard input.
    3. The program asks how many oranges you want. It explains that a number between 1
    and 100 is required. It receives keyboard input.
    4. The program outputs the correct amount of money.
    5. The program uses one function to calculate the price of the apples and another function
    to calculate the price of the oranges.
    6. The program does not use the If statement.
    7. The program is easy to use.
    8. The program does not perform unnecessary tasks.
    9. The source code is contained in one file and is not unnecessarily long.
    10. The source code utilizes white space properly and consistently to enhance legibility.
    11. The variable/function names are chosen and typed/written in a way that clearly explains
    their purposes. The naming style is consistent throughout the whole program.
    12. The source contains effective, consistent comments, especially near any complex or
    obscure sections of code.

    I am using static variables. I need help with the Apple function. How do I set it up as in I can't do : static float applecost/=2. Because if the person buys 3 apples, 3/2 does not equal 2 as it should. How do I do it?

    Side note: Is there anyway that I can upload what I've done in the program so far?

    "The world will look up and shout 'Save us!!!', and I will whisper 'No.'". -Rorschach, Watchmen
  • #2
    AndyPants
    Civilian
    • Oct 2004
    • 756
    • Pants9000

    Sounds like you're on track as far as wrapping your head around it and getting it started. I'm not the most versed programmer here as far as C++ goes but think about maybe setting up vars that are specially used for the "sale" and check to see if they are set and use them to override the regular price (some sort of if then statement?) Half of what you need to get out of this practice is being able to figure it out on your own but I'm sure there are people around that could help you with some syntax so as for
    Side note: Is there anyway that I can upload what I've done in the program so far?
    just use the "code" tag here in the forums. It's the one up with the # symbol when you are making a new post.
    Example:
    Code:
    this is code
    this is more code

    Comment

    • #3
      Capthemfoos
      Honorary DSA

      This is my code so far:

      Code:
      #include<iostream>
      using namespace std
      
      float applefunc(float)// Apple function prototype
      float orangefunc(float)// Orange function prototype
      
      int main()
      {
      	cout << "Welcome to the Sunny Day Grocery Store!!!" << endl;
      
      	cout << "We have two astounding deals for you today!" << endl;
      
      	cout << "(1)Buy 1 apple, get one free!!!(2)The amount of oranges you buy will be ther percentage you get off your bill!!!" << endl;// deals
      	
      	cout << "An apple costs $1.00 and an orange costs $1.50. You can't buy more than 100 of each item." << endl;//prices
      
      	static int myapples;//static int for inter-function use
      	static int myoranges;//"
      	
      	static float applecost;//inter-function use, necessary for calculations
      	static float orangecost;//"
      
      	cout << "How many apples do you wish to buy?" << endl;
      	cin >> static int myapples;// user input
      
      	cout << "How many oranges do you wish to buy?" << endl;
      	cin >> static int myoranges;// user input
      	system("PAUSE");
      	return 0;
      }
      
      float applefunc()//function
      {
      	static float applecost = static int myapples * 1.00;
      	static float applecost/= 2;
      Its still a work in progress, as many necessary things are still left out. THe problem is at the bottom.

      "The world will look up and shout 'Save us!!!', and I will whisper 'No.'". -Rorschach, Watchmen

      Comment

      • #4
        RaTix
        Emperor

        You can run a modulo % on the amount of apples purchased to determine if they are even or Odd amount. Do it by 2 and it will return the remainder. If the number is Even it will return the value of 0, if odd it will return the value of 1.

        I am not too familiar with C++, but PHP which I am, is very similar in design. I'm not trying to do your work for you, but maybe this will help explain how to do it better. Plus I couldn't resist the challenge of doing it myself.

        Code:
        #include<iostream>
        using namespace std
        
        float applefunc(float)// Apple function prototype
        float orangefunc(float)// Orange function prototype
        
        int main()
        {
        	cout << "Welcome to the Sunny Day Grocery Store!!!" << endl;
        
        	cout << "We have two astounding deals for you today!" << endl;
        
        	cout << "(1)Buy 1 apple, get one free!!!(2)The amount of oranges you buy will be ther percentage you get off your bill!!!" << endl;// deals
        	
        	cout << "An apple costs $1.00 and an orange costs $1.50. You can't buy more than 100 of each item." << endl;//prices
        
        	static int myapples;//static int for inter-function use
        	static int myoranges;//"
        	
        	static float applecost;//inter-function use, necessary for calculations
        	static float orangecost;//"
        
        	cout << "How many apples do you wish to buy?" << endl;
        	cin >> static int myapples;// user input
        
            if (myapples > 100) //Determines if the user entered a number greeater then the limited 100
            {
                cout << "Apple limit Exceeded" << endl;
                cout << "How many apples do you wish to buy?" << endl;
        	    cin >> static int myapples;// user input
        	}	
               Else
        	{   
            cout << "How many oranges do you wish to buy?" << endl;
        	cin >> static int myoranges;// user input
        	system("PAUSE");
        	return 0;
        	}
        }
        if (myapples % 2 = 1); //Determines if the amount of apples are even or odd. Even = Special deal. 
        {
        TotalAppleCost = (myapples / 2)++; //If the apples amount returns as an odd number, then the total is divided by 2, as only half are being charged, and then 1 is added. So if you have 13 apples, you divide by 2 and get 6, then add 1 and thats the amount of apples they are actually paying for.  
        }
        Else 
        {
        TotalAppleCost = (myapple / 2); //if it's even number of apples, say 14, you divide by 2 and thats what they are actually paying for. In this case 7. 
        }
        float applefunc()//function
        {
        	static float TotalAppleCost = static int myapples * 1.00;
        }
        As I said, I'm not too familiar with C++, so you might want to double check that.

        There are quite a few sites that help guide you through the variables and operators and all that good stuff if you need a quick reference.
        "POWER!!! UNLIMITED POOWWWEEEER!!!!!!

        "Tell me what you regard as your greatest strength, so I will know how best to undermine you; tell me of your greatest fear, so I will know which I must force you to face; tell me what you cherish most, so I will know what to take from you; and tell me what you crave, so that I might deny you."
        ?Darth Plagueis

        "Peace is a lie, there is only passion. Through passion, I gain strength. Through strength, I gain power. Through power, I gain victory. Through victory, my chains are broken. The Force shall free me."

        Comment

        • #5
          Capthemfoos
          Honorary DSA

          Thanks. I'll tackle this tommorow and see what I can do.

          "The world will look up and shout 'Save us!!!', and I will whisper 'No.'". -Rorschach, Watchmen

          Comment

          Ad

          Collapse
          Working...