Bulky...can you make it simpler

This is a discussion on Bulky...can you make it simpler within the C++ Programming forums, part of the General Programming Boards category; Code: #include <iostream> using namespace std; int main() { int input ,number = 0,mult = 1,header = 1; cout<<"Enter a ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    91

    Bulky...can you make it simpler

    Code:
    #include <iostream>
    using namespace std;
    
    int main()
    {
    int input ,number = 0,mult = 1,header = 1;
    cout<<"Enter a number from 2 to 15 ";
    cin>>input;
    if (input > 15 || input < 2)
    {
    cout<<"invalid value, please enter a number from 2 to 15 only."<<endl;
    }
    else
    {
    cout<<"    ";
    
    while (header <= input)
    {
    	if (header > 9)
    	{
    		cout<<"  "<<header;
    		header++;
    	}
    	else
    	{
    		cout<<"   "<<header;
    		header++;
    	}
    	
    }
    	cout<<"\n";
    	cout<<"    .---";
    	header = 1;
    while (header++ < input)
    {
    	cout<<"----";
    }
    	cout<<"\n";
    while (number < input)
    {	
    	number++;
    	if (number <= 9)
    	cout<<" "<<number<<" |";
    	else
    	cout<<number<<" |";
    	while (mult <= input)
    	{
    	
    		if ((number * mult) <= 9) 
    		{
    			cout<<"   ";
    		}
    		if ((number * mult) > 9 && (number * mult) <= 99)
    		{
    			cout<<"  ";
    		}
    		if ((number * mult) > 99) 
    		{
    			cout<<" ";
    		}
    		cout<<number * mult;
    		mult++;
    	}
    	mult = 1;
    	cout<<"\n";
    }
    }
    }

  2. #2
    Chinese pâté foxman's Avatar
    Join Date
    Jul 2007
    Location
    Canada
    Posts
    404
    To answer to your question, yes.
    I hate real numbers.

  3. #3
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You could use setw() to define the width of integer output.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  4. #4
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    Also, practice your indenting a little more. It's pretty hard to read like that.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Establishing 'make clean' with GNU make
    By Jesdisciple in forum C Programming
    Replies: 9
    Last Post: 04-11-2009, 10:10 AM
  2. How to make a Packet sniffer/filter?
    By shown in forum C++ Programming
    Replies: 2
    Last Post: 02-22-2009, 09:51 PM
  3. HELP!wanting to make full screen game windowed
    By rented in forum Game Programming
    Replies: 3
    Last Post: 06-11-2004, 05:19 AM
  4. make all rule
    By duffy in forum C Programming
    Replies: 9
    Last Post: 09-11-2003, 02:05 PM
  5. Replies: 6
    Last Post: 04-20-2002, 07:35 PM

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