# Looping Array of Numbers

Page 1 of 1

## 9 Replies - 750 Views - Last Post: 04 December 2010 - 05:21 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=203538&amp;s=451f8c985d9d427ed0aff89d48c4d238&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 issyl

Reputation: -5
• Posts: 118
• Joined: 25-October 10

# Looping Array of Numbers

Posted 04 December 2010 - 02:35 AM

How can i fix this? I want the user to input 5 numbers and then print it out. The problem was after i input 5 numbers it display nothing how can i fix it?

```#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(void)
{
char Numbers[5];
int i = 0, x;
clrscr();

while(i <= 4)

{
printf("Enter a number: ");
scanf("%d", &x);
Numbers[i] = x;
i++;
}

while(Numbers[i] != '\0')
{
cout << Numbers[i] << endl;
i++;
}
getch();

}

```

Is This A Good Question/Topic? 0

## Replies To: Looping Array of Numbers

### #2 no2pencil

• Professor Snuggly Pants

Reputation: 6642
• Posts: 30,931
• Joined: 10-May 07

## Re: Looping Array of Numbers

Posted 04 December 2010 - 02:40 AM

After you've gathered all the values, you have to reset the value of i to zero.

### #3 janotte

• code > sword

Reputation: 991
• Posts: 5,141
• Joined: 28-September 06

## Re: Looping Array of Numbers

Posted 04 December 2010 - 02:43 AM

```while(Numbers[i] != '\0')

```

You can't just recycle ideas from old programs you didn't understand.
You do need to think about what is happening in this program and what you want to do.

### #4 issyl

Reputation: -5
• Posts: 118
• Joined: 25-October 10

## Re: Looping Array of Numbers

Posted 04 December 2010 - 02:49 AM

but look at this... after i made an easier program, it display unknown numbers..

```#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(void)
{
char Numbers[5];
Numbers[0] = 5;
Numbers[1] = 4;
Numbers[2] = 3;
Numbers[3] = 2;
Numbers[4] = 1;
int i = 0;
clrscr();

while(Numbers[i] != '\0')
{
printf("%d\n", &Numbers[i]);
i++;
}
getch();

}

```

it displays - numbers

pls i dont know how... we are already in file handling and now that i have to use this kind of problem i cant remember or i dont know rather ..

```#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(void)
{
char Numbers[5];
Numbers[0] = 5;
Numbers[1] = 4;
Numbers[2] = 3;
Numbers[3] = 2;
Numbers[4] = 1;
int i = 0;
clrscr();

while(i != 5)
{
printf("%d\n", &Numbers[i]);
i++;
}
getch();

}

```

im trying but it cant help it ...

This post has been edited by issyl: 04 December 2010 - 02:45 AM

### #5 issyl

Reputation: -5
• Posts: 118
• Joined: 25-October 10

## Re: Looping Array of Numbers

Posted 04 December 2010 - 03:02 AM

nopencil may i know how you convert this to c++?

```#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(void)
{
char Numbers[5];
Numbers[0] = 5;
Numbers[1] = 4;
Numbers[2] = 3;
Numbers[3] = 2;
Numbers[4] = 1;
int i = 0;
clrscr();

for(i = 0; i <= 4; i++)
{
/* I failed on this Numbers[i] nevermind my last post im so stupid &&&&&&  :(/> */
cout << Numbers[i] << endl;
//printf("%d\n", Numbers[i]);
}

getch();
}

```

### #6 Bench

• D.I.C Lover

Reputation: 944
• Posts: 2,464
• Joined: 20-August 07

## Re: Looping Array of Numbers

Posted 04 December 2010 - 03:06 AM

issyl, on 04 December 2010 - 09:49 AM, said:

```	char Numbers[5];
Numbers[0] = 5;
Numbers[1] = 4;
Numbers[2] = 3;
Numbers[3] = 2;
Numbers[4] = 1;
int i = 0;
clrscr();

while(i != 5)
{
printf("%d\n", &Numbers[i]);

```

im trying but it cant help it ...
The problem is in the way you're using printf. Do you understand what the & operator does? If not look it up in your book. Also read up on the usage of the printf function if you are not sure how to pass arguments, and the exact meaning of format specifiers.

As someone else has already mentioned in this thread - you need to understand the code you are writing, because you will never get anywhere if all you're doing is throwing random symbols in and hoping for the best.

This post has been edited by Bench: 04 December 2010 - 03:08 AM

### #7 issyl

Reputation: -5
• Posts: 118
• Joined: 25-October 10

## Re: Looping Array of Numbers

Posted 04 December 2010 - 03:31 AM

can anyone convert this line of code:

```#include <stdio.h>
#include <conio.h>
#include <iostream.h>

void main(void)
{
char Numbers[5];
Numbers[0] = 5;
Numbers[1] = 4;
Numbers[2] = 3;
Numbers[3] = 2;
Numbers[4] = 1;
int i = 0;
clrscr();

for(i = 0; i <= 4; i++)
{
/* THIS COUT << NUMBERS[I] << ENDL; DONT WORK... HOW CAN I FIX THIS ONE?
THE ORIGINAL IS printf("%d\n", Numbers[i]); BUT TO CONVERT TO C++ HOW? ANYONE? */
cout << Numbers[i] << endl;
//printf("%d\n", Numbers[i]);
}

/*
for ( day = 1; day <= DAYS_IN_WEEK; ++day)
printf("Sales for day %hi = %5hi\n", day, sales[day - 1]);
*/
getch();
}

```

### #8 Salem_c

• void main'ers are DOOMED

Reputation: 2160
• Posts: 4,225
• Joined: 30-May 10

## Re: Looping Array of Numbers

Posted 04 December 2010 - 04:30 AM

It IS C++.
What you need to do it tell us something more informative than "it doesn't work".

But then again, you're using #include <iostream.h>, which has been obsolete for over a decade now, and you're using void main which has never been valid. So who knows what kind of fossil compiler you're using.

### #9 budfox

Reputation: 2
• Posts: 10
• Joined: 03-December 10

## Re: Looping Array of Numbers

Posted 04 December 2010 - 04:45 AM

If you read ints you must define ints (and not chars).
Remove the non portable conio stuff from your programs and don't mix C++ and C codeparts.
```#include <stdio.h>

#define NNUM 5
int main()
{
int Numbers[NNUM];
int i = 0;

while(i < NNUM)
{
printf("Enter a number: ");
scanf("%d", &Numbers[i++]);
}

i=0;
while(i < NNUM)
{
printf("%d\n",Numbers[i++]);
}
return 0;
}

```

• Saucy!

Reputation: 6246
• Posts: 24,014
• Joined: 23-August 08

## Re: Looping Array of Numbers

Posted 04 December 2010 - 05:21 AM

issyl, you have GOT to stop opening up duplicate topics. It's not going to get you help for your copy & paste code endeavors any more quickly; it's only serving to annoy me and others.

Merged duplicate topics.