Thread: A wee bit of help needed

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Question A wee bit of help needed

    I need to create an application that will display the multiplication table for a number entered. The application should ask the user to enter a number, check if number is between 2 and 12 (inclusive). If number entered is not in the range, should display error message. Otherwise display the multiplication table.

    i have to use logical operators to check for valid number and the for loop for making the table.

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Location
    NJ
    Posts
    1,141
    Post problems with you have with the homework.. not just your homework.
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

  3. #3
    S­énior Member
    Join Date
    Jan 2002
    Posts
    982
    If you want help your probably going to have to post a valid atempt (unless you want to email me privately with your credit card number, in which case I'd be more than happy to do your homework ).

    You could use a for loop.

  4. #4
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    or you could post your credit card number here and we'd all be glad to help you

  5. #5
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    .

  6. #6
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Jesus...
    Code:
    int i;
    int table;
    
    cout << "What times table do you want: ";
    cin >> table;
    
    for (i = 1; i <= 12; i++)
       cout << i << " times " << table << " = " << (i * table) << ".\n";

  7. #7
    Registered User
    Join Date
    Feb 2002
    Posts
    5

    Thankx, Sam

    Ahhh, now i see where i was going wrong. I just started C++ a month ago, and have just recently "gotten" it.
    I have been using this site frequently to use the tutorials, and thought the message board would be helpful.
    thank you again

  8. #8
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    Jeez dude, this is lame. I just started on C++ 5 days ago and I could have dreamt up that code in a sec... I sure as hell hope for you you're gonna catch on a bit quicker.

  9. #9
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    Well I thought of being a bit more constructive here, so I went ahead and added some to what samGwilliam made:


    Code:
    #include <iostream.h>
    
    int main()
    {
         int i;
         int num;
         int goodToGo = 0;
         char again;
    
         while (!goodToGo)
         {
    	cout<<"Please enter the table you want"<< endl << endl;
    	cin>>num;
    	cout<<endl;
    		
    	if (num>=1 && num<=10)
    	{
    	     goodToGo = 1;
    
    	     cout<<"THE TABLE OF "<< num << ":" << endl;
    	     cout<<"----------------"<< endl;
    	
    	     for (i=1; i<11; i++)
    	     {
    	          if (i<10)
    	          {
    	               cout<< i << "  times " << num << " = " << i*num << endl;
    	          }
    	          else
    	          {
    	               cout<< i << " times " << num << " = " << i*num << endl;
    	          }
    	     }
    
    	     cout<< endl << "Would you like to see another table?" << endl;
    	     cout<< "Press y/n: ";
    	     cin>> again;
    
    	     if (again == 'y')
    	     {
    	          goodToGo = 0;
    	          // Best to clear screen here...
    	          // See http://www.cprogramming.com/boardfaq.html#clear on how to do that
    	     }
    	     else
    	     {
    	         cout<< endl << "Have a nice day." << endl;
    	     }
    	}
    	else
    	{
    	     cout<<"The number you supplied is not in the range of 1 to 10"<<endl;
    	}
         }
         return 0;
    }
    yur welcome.
    Last edited by Mbrio; 02-08-2002 at 10:04 PM.

  10. #10
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    Nice, but a tad overkill, no?

  11. #11
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    Yeah well, i'm an interaction designer. I aim to please

  12. #12
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382

    Unhappy

    Cool.

    Code:
    #include <iostream.h>
    #include <stdlib.h>
    
    class table
    {
    private:
    
       int tableType;
    
    public:
    
       table (int type);
       void display (int tableSize);
    };
    
    table::table (int type)
    {
       tableType = type;
    }
    
    void table::display (int tableSize)
    {
       int i;
    
       cout << "The " << tableType << " times table:\n";
    
       for (i = 1; i <= tableSize; i++)
          cout << i << " times " << tableType << " = " << (i * tableType) << ".\n";
    }
    
    int main (int argc, char *argv [])
    {
        table *myTable;
    
       if (argc != 3)
       {
           cout << "Usage: " << argv [0] << " tableType tableSize.\n";
           exit (1);
       }
    
       myTable = new table (atoi (argv [1]));
       myTable->display (atoi (argv [2]));
    
       cout << "Have a nice day!\n";
    
       delete myTable;
    
       return 0;
    }
    Last edited by samGwilliam; 02-08-2002 at 10:24 PM.
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  13. #13
    Registered User
    Join Date
    Feb 2002
    Posts
    27
    Heh samG, can't compile it man.

  14. #14
    Registered User samGwilliam's Avatar
    Join Date
    Feb 2002
    Location
    Newport
    Posts
    382
    char *argv []
    Current Setup: Win 10 with Code::Blocks 17.12 (GNU GCC)

  15. #15
    Registered User
    Join Date
    Feb 2002
    Posts
    27

    Thumbs up

    Nice work. Thumbs up!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 16
    Last Post: 11-23-2007, 01:48 PM
  2. bit value check efficiency
    By George2 in forum C Programming
    Replies: 5
    Last Post: 11-05-2007, 07:59 AM
  3. A Question About Unit Testing
    By Tonto in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 08:22 PM
  4. bit of support needed
    By momo20016 in forum C Programming
    Replies: 2
    Last Post: 12-26-2002, 10:29 AM