#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();
}
Looping Array of Numbers
Page 1 of 19 Replies - 365 Views - Last Post: 04 December 2010 - 05:21 AM
#1
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?
Replies To: Looping Array of Numbers
#2
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
Re: Looping Array of Numbers
Posted 04 December 2010 - 02:43 AM
what is this about?
Where is your thinking at?
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.
while(Numbers[i] != '\0')
Where is your thinking at?
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
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..
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 ..
im trying but it cant help it ...
#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
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
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 ...
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
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
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.
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
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.
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;
}
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote







|