Mutiliplcation Program that uses a (do, while, and for loop)?

This is a discussion on Mutiliplcation Program that uses a (do, while, and for loop)? within the C++ Programming forums, part of the General Programming Boards category; Write a program that 1. Uses the C++ iteration constructs (while, do, for). 2. Use Boolean variables and expressions to ...

  1. #1
    Registered User
    Join Date
    Oct 2008
    Posts
    13

    Mutiliplcation Program that uses a (do, while, and for loop)?

    Write a program that

    1. Uses the C++ iteration constructs (while, do, for).
    2. Use Boolean variables and expressions to control iterations.




    Project Requirements:
    1) Develop a multiplication table test program.

    2) The Multiplication Table should complete the following:

    i) Ask the user for the maximum value of the multiplication table, call this variable tablemax. tablemax is the largest value the table will test, so if the user enters 10 then all tests will run from 1 to 10.

    ii) Ask the user for the number that they wish to practice or enter the letter Q to quit. This will need to be done in two statements, first ask the user if they wish to continue, typing 'Q' to quit or anything else to continue.

    iii) If Q is entered the program exits.

    iv) If a number is entered, test it to insure it is a positive number and less than or equal to the tablemax value entered earlier. If it fails this criteria display and error message and ask the user to enter a new number, (step ii).

    v) Here is sample output from the driver program:



    Enter the largest number you would like your multiplication table to test: 5
    To practice your multiplication,
    enter the positive number you want to practice, or enter Q to quit.
    You will practice this number up to 5


    Enter a number: 3
    3 x 1 is equal to: 3
    Very good, that is the correct answer
    3 x 2 is equal to: 6
    Very good, that is the correct answer
    3 x 3 is equal to: 9
    Very good, that is the correct answer
    3 x 4 is equal to: 7
    That is incorrect, the correct answer is: 12
    3 x 5 is equal to: 15
    Very good, that is the correct answer

    You have completed your multiplication tables for: 3


    To practice your multiplication,
    enter the positive number you want to practice, or enter Q to quit.
    You will practice this number up to 5
    Enter a number: q





    Implementation Notes:

    1. You should use both the for loop and the while loop constructions in this program.
    2. The for loop construction is used when a definite number of iterations can be determined prior to the loop starting such as for generating the multiplication table.
    3. A while or do loop is used when the number of iterations is indefinite and determined while the loop is executing to determine if the user wants to try a new table or quit





    Okay, so my main problem is how to write out the math for the multiplication table using the 3 loops (do, while, and for). I am totally lost as to where I start with the math. My textbook does not explain this type of math involved in this homework.

    This is my code so far:

    Code:
    #include <iostream>
       using namespace std;
    
        int main()
       {
          int largest_number, positive_number;
       
       
       
       
          cout << " Enter the largest number you would like your multiplication table to test :\n ";
          cin >> largest_number;
          cout << " To practice your multiplication,\n ";
          cout << "enter the positive number you want to practice, or enter Q to quit.\n ";
          cout << "You will practice this number up to " << largest_number << "\n ";
          cout << "Enter a number :\n ";
          cin >> positive_number;
       
       
       
       
       
       
       
       
       
       
       
          return 0;
       }

    My output in jGrasp after I compile and run it it is:

    Code:
    
     ----jGRASP exec: H:\My Documents\a.exe
    
     Enter the largest number you would like your multiplication table to test :
     5
     To practice your multiplication,
     enter the positive number you want to practice, or enter Q to quit.
     You will practice this number up to 5
     Enter a number :
     3
    
     ----jGRASP: operation complete.

    Can anyone help me?

    Thank you, Debbie

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    You don't loop

    Example:
    Code:
    foreach number to largest_number
      foreach multiple to positive_number
        cout << number << " x " << multiple << " = " << number * multiple;
      loop
    loop

  3. #3
    Registered User
    Join Date
    Oct 2008
    Posts
    13
    I get how you compute it...but how do you incorporate the loops that my instructor asks for?

  4. #4
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    How would I change my pseudo code into C++? I am really honestly not trying to be difficult. I just want to make you understand how loops are organized in C++.

    for([initialize a count] ; [test for the end] ; [increment])

  5. #5
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,643
    >> My textbook does not explain this type of math involved in this homework.

    Perhaps, but surely it covers looping constructs. I'd recommend setting aside the homework for a bit and spending some time reading through a few good C++ books.
    Code:
    if( numeric_limits< byte >::digits != bits_per_byte )
        error( "program requires bits_per_byte-bit bytes" );
    24bbs.cpp

Popular pages Recent additions subscribe to a feed

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