How To Solve This Problem

I want to make a program like this using while please help me



jumlah digit 9

000000000 ///jumlah digit menentukan panjang digit
000000001 ///per digit diawali 0
000000002 ///digit paling kiri = int++
000000003 ///digit paling kiri = int++
000000004 ///digit paling kiri = int++
000000005 ///digit paling kiri = int++
000000006 ///digit paling kiri = int++
000000007 ///digit paling kiri = int++
000000008 ///digit paling kiri = int++
000000009 ///digit paling kiri = int++
000000010 ///digit paling kiri = int++ && setelah int mencapai angka sembilan maka digit bergeser ke kanan dan digit yg telah mencapai >9 direset kembali jadi 0



in english
9 digit number

000000000 /// number of digits determines length of digits
000000001 /// per digit starting with 0
000000002 /// leftmost digit = int ++
000000003 /// leftmost digit = int ++
000000004 /// leftmost digit = int ++
000000005 /// leftmost digit = int ++
000000006 /// leftmost digit = int ++
000000007 /// leftmost digit = int ++
000000008 /// leftmost digit = int ++
000000009 /// leftmost digit = int ++
000000010 /// leftmost digit = int ++ && after the int reaches nine then the digit shifts to the right and the digit that has reached> 9 is reset to 0



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
include <iostream>
using namespace std;


main()
{
int x=0,y=0,z=0;
 
cout<<"Masukan Jumlah Baris"<<endl;
cin>>x;

	while(z<=x)
	{
	z++;
	cout<<y;
	if(z=x)
	{
	 	
	}
	
	}
}  
This looks to be a program to determine the digital root of a number (+ve integer)
My donkey?
Let me know what it looks like? I want it to be output like a calculator but only the digits are determined,, please help me
maybe its just like a counter but the digit are determined
please help me
What is is meant to do?
Here is a start:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>

using namespace std;

int main()
{
    int x = 0, y = 0, z = 0;
    
    cout << "Masukan Jumlah Baris (enter the number of rows): ";
    cin >> x;
    
    while(z <= x)
    {
        z++;
        cout << y;
        if(z == x)
        {
            cout << "Pergi mana?\n";
        }
    }
    cout << '\n';
}
Last edited on

Masukan Jumlah Baris (enter the number of rows): 9
000000000Pergi mana?0


thats the output of your code and how to make it count left most digit?
thats the output of your code and how to make it count left most digit?
Really? I think it is the output of your code. All I have done is made a few repairs to get it running.

So which is the leftmost digit?

000000000 
000000001
000000002 
000000003 
000000004 
000000005 
000000006 
000000007 
000000008 
000000009 
000000010 


i am so sorry not left but right most digit ,,, i am to rush to make it ,, i make it for tommorow at programmer class ,, the trainer want all of we to make some program about while ,, i panicked ,, sorry ,,
OK, so what is the rightmost digit.
Why count, if you can format?
1
2
3
4
5
6
7
8
9
10
11
#include <iostream>
#include <iomanip>

int main()
{
    std::cout << std::setfill('0');
    for ( unsigned long num = 0; num < 25; ++num )
    {
        std::cout << std::setw( 9 ) << num << '\n';
    }
}
You can translate this to while's use something other than C-style arrays if you like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>

void display(int* anArray, int limit)
{
    for(int i = 0; i < limit; i++)
        std::cout << anArray[i];
    std::cout << '\n';
}

void add(int* aArray, int* bArray, int limit)
{
    int carry_over = 0;
    int temp;
    
    for(int i = limit - 1; i >= 0; i--)
    {
        temp = aArray[i] + bArray[i] + carry_over;
        
        carry_over = temp / 10;
        temp = temp % 10;
        
        aArray[i] = temp;
    }
}

int main()
{
    int size = 0;
    std::cout << "Masukan Jumlah Baris (enter the number of rows): ";
    std::cin >> size;
    
    int* array_A = new int[size]{0};
    
    int* array_B = new int[size]{0};
    array_B[size - 1] = 1;
    
    for(int i = 0; i < 1000; i++)// 1000 chosen for convenience
    {
        add(array_A, array_B, size);
        display(array_A, size);
    }
}


It wasn't digital roots :(
Last edited on
Thanks For All Of You ,, Your Help Are So very valuable for me,, thank you
your suggestion code are so close to my expetation
Bagus, now just green tick to show thread is complete.
one thing again please,, can you explain to me about void add and display ,, please
Each of the 2 functions ( see http://www.cplusplus.com/doc/tutorial/functions/ for a good tutorial ) perform a job.

If you send details of the array and its size to display(...) the display function will print out the elements of the array.

If you send details of 2 arrays and their (same) size to add(...) the add function will add them.

Both function do their job but don't send anything back to where they were called in main() - that is shown as void - zip, nada, nothing, kosong ) All the work is done inside the function.
OK THANK YOU VERY VERY MUCH ,,,BECAUSE YOUR ALL HELP ,, I'LL BE INCLUDED IN THE PROGRAMING COMPETITION WISH ME LUCK PLEASE ,, THANK YOU VERY VERY MUCH ,,TOLONG JANGAN BOSAN UNTUK MEMBANTU MENGAJARI SAYA , SAYA PERLU SEKALI BANTUAN ANDA SEMUA

PLEASE DON'T BORED TO HELP & TEACH ME, I NEED HELP FROM YOU ALL
Topic archived. No new replies allowed.