Need help with a basic while loop program

This is a discussion on Need help with a basic while loop program within the C++ Programming forums, part of the General Programming Boards category; So here is the problem. Provide a C++ solution for problem 1 from the end of chapter 7 using a ...

  1. #1
    Registered User
    Join Date
    Mar 2012
    Posts
    2

    Need help with a basic while loop program

    So here is the problem.

    Provide a C++ solution for problem 1 from the end of chapter 7 using a while loop. When you include the output at the end of your program, be sure to demonstrate having tested all paths in your code.


    The Last Stop Boutique is having a five-day sale. Each day, starting on Monday, the price will drop 10% of the previous day’s price. For example, if the original price of a product is $20.00, the sale price on Monday would be $18.00 (10% less than the original price). On Tuesday the sale price would be $16.20 (10% less than Monday) and so on. Develop a solution that will calculate the price of an item for each of the five days, given the original price. Test the solution for an item costing $10.00


    Also,


    Turn in a Flow Chart or Algorithm, an IPO and a Data Dictionary for this program.


    here is what I have so far.

    Code:
    #include <iostream>
    using namespace::std; 
    int main() {
         int counter = 1;
         int n = 5; 
         int Price = 0; 
         int Sum; 
         int Discount = 0.1; 
    {
         cout << "Enter The Original Price: "; cin >> Price;
    }
    
         while (counter <= n)
         {
              Price = Price - (Price * Discount);
         }
         return 0;
    }
    What am I doing wrong. The text book that we are using is not helping at all. Are there any suggestions for a good text to help with this basic c++ programming.
    Last edited by Salem; 03-03-2012 at 12:59 AM. Reason: tag cleanup

  2. #2
    Registered User
    Join Date
    Mar 2012
    Posts
    2
    I thought I understood this but am having no luck with this code. I am missing something and I'm playing with the code and reading the code and trying different things with no luck. Any help would be much appreciated.

  3. #3
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,556
    Look at line 13.
    Where in the loop do you change counter or n?

    If neither change, the loop runs forever (or not at all).
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Basic Loop
    By DuckCowMooQuack in forum C Programming
    Replies: 17
    Last Post: 10-20-2011, 10:37 AM
  2. Basic C program help
    By exus69 in forum C Programming
    Replies: 3
    Last Post: 05-20-2011, 07:00 AM
  3. Basic C# Program
    By fishchunks in forum C Programming
    Replies: 1
    Last Post: 02-26-2011, 01:05 PM
  4. using for loop and functions to create a basic menu
    By sunandstars in forum C Programming
    Replies: 2
    Last Post: 02-19-2011, 01:12 PM
  5. Basic Loop Question
    By demiurge in forum C++ Programming
    Replies: 1
    Last Post: 12-02-2009, 08:10 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21