Jump to content

Some help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
19 replies to this topic

#1
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
The question is Write a program that will get a number from the user and print that number that time on the console window

is this correct?

{

int n;

for(int i=n ; i<=n ;i)

        {

          cout<<"\n "<<i;

         }

}

is this correct ?

And i have no clue how to do this
Write a program that will print the multiples of the given number and divide them in rows and columns.(you can use escape sequences)

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
You have to use cin to get input from the user.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
sorry for that mistake and i corrected it and there was also another logical error which I also fixed but can u help with the 2nd part?

#4
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
To put things in columns on a console, use tabs:
"200\t2\t100" will display something like this

200     2       100

In other words, tabs move the cursor right to the (a multiple of 8)th column, whichever is closest.

#5
Steve.L

Steve.L

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 444 posts
This code will return the table for multiples up to 9. I'll leave it to you to figure out how to get specific number's multiples based on user input.

#include <iostream>
using namespace std;

void PrintMultiples();

int main()
{
    PrintMultiples();
	
    system("PAUSE");
    return EXIT_SUCCESS;
}

void PrintMultiples()
{
    for (int i = 1; i < 10; i++) {
        cout << i << "| ";
        for(int j = 1; j < 10; j++) cout << j * i << '\t';
        cout << "\n";
    }
}


#6
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
1| 1	2	3	4	5	6	7	8	9	
2| 2	4	6	8	10	12	14	16	18	
3| 3	6	9	12	15	18	21	24	27	
4| 4	8	12	16	20	24	28	32	36	
5| 5	10	15	20	25	30	35	40	45	
6| 6	12	18	24	30	36	42	48	54	
7| 7	14	21	28	35	42	49	56	63	
8| 8	16	24	32	40	48	56	64	72	
9| 9	18	27	36	45	54	63	72	81	
Nice! (I edited out the windows-specific call to system()).

#7
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
another thing i forgot to mention that if the number is 5 then the multiples of 5 should be in 5 rows and 5 columns...

#8
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Wha? I don't understand.

#9
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
like this
Input number : 4

4 8 12 16
20 24 28 32
36 40 44 48
52 56 69 64

#10
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
Here's pseudocode:
get number from user, set x to it.
set y, z, w to the same as x.
while z is not 0(
y = w
while y is not 0(
print x, tab.
x = x + w.
decrement y.
)
output a newline.
decrement z.
)

#11
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
it doesnt works i think it doesnt gives any out put :'(

#12
Aereshaa

Aereshaa

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 790 posts
That is pseudocode. I'm not so familiar with c++.