Repeating a simple calculation

This is a discussion on Repeating a simple calculation within the C++ Programming forums, part of the General Programming Boards category; Code: //File name: PP1Ch2-cereal-weight //Description: a) A program to weight in ounces and output it in tons. // b) The ...

  1. #1
    Registered User FloatingPoint's Avatar
    Join Date
    Jun 2003
    Posts
    191

    Repeating a simple calculation

    Code:
    //File name: PP1Ch2-cereal-weight
    //Description: a) A program to weight in ounces and output it in tons.
    //             b) The number of boxes needed to yield a ton of cereal.
    //Last update: 21/7/2003
    
    
    #include <iostream.h>
    #include <stdlib.h>
    
    int main()
    {
          cout.setf(ios::fixed);
          cout.setf(ios::showpoint);
          cout.precision(4);
    
          double package_weight, package_weight_ton,
                 number_of_packages;
    
          cout << "Enter the weight of a cereal package in ounces: ";
          cin  >> package_weight;
    
          // A ton is 35723.92 oz.
    
          package_weight_ton = package_weight / 35273.92;
          number_of_packages = 1 / (package_weight / 35273.92);
    
          cout << "The weight of the package in tons is: " << package_weight_ton << " tons.\n";
    
          cout.precision(1);
    
          cout << "A number of " << number_of_packages << " packages are needed to satisfy a ton of cereal.\n";
    
          system("PAUSE");
          return 0;
    }
    I'm doing this question which asks that the program above allows a user to repeat this calculation as often as a user wishes.

    That's instead of press any key to continue and then the program exits, the program should prompt again for user input when the user presses a key to continue.

    Do I need to use if-else statements here? If so where should I put them?

    Thanx.

  2. #2
    Registered User FloatingPoint's Avatar
    Join Date
    Jun 2003
    Posts
    191
    Thanx.

    But where should I put it?

    Sorry for being lame, guess I'm a slow learner..
    Come cast your shadow over me
    and I'll cast mine all over thee
    Take me away, into the shades
    where there is no light of day

  3. #3
    Registered User FloatingPoint's Avatar
    Join Date
    Jun 2003
    Posts
    191
    Thanx, got that.
    Come cast your shadow over me
    and I'll cast mine all over thee
    Take me away, into the shades
    where there is no light of day

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple message encryption
    By Vicious in forum C++ Programming
    Replies: 10
    Last Post: 11-07-2004, 10:48 PM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Simple calculation not working, need help
    By Summonerur in forum C Programming
    Replies: 20
    Last Post: 09-24-2004, 02:53 PM
  4. Simple simple program
    By Ryback in forum C++ Programming
    Replies: 10
    Last Post: 09-09-2004, 05:48 AM
  5. Need help with simple DAQ program
    By canada-paul in forum C++ Programming
    Replies: 12
    Last Post: 03-15-2002, 07:52 AM

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