![]() |
| | #1 |
| Registered User Join Date: Aug 2008
Posts: 3
| Noob question! Code completion - Array challenge I've decided to teach myself C++. So for the past week or so I've been reading the tutorials on this site, doing the examples etc. I finished the tutorials and decided to try the challenges. And I got stuck on the first!!! After trying unsuccessfully to get my program to work, I looked at Cprogramming.com's solution, compiled it, ran it, and even the solution doesn't work! When running it fills in the element of the array (I presume) but it does not list them(I take list to mean print) and instead just exits. So, is my compiler broken? Or is there some incredibly noobish mistake that i can't see(most likely) ![]() Below is the solution, as posted by Cprogramming.com: When completed, the following program should first fill in (by asking the user for input) and then list all the elements in an array: Code: #include <iostream>
using namespace std;
int main()
{
int array[8];
for(int x=0; x<8; x++)
cin>> array[x];
for(int x=0; x<8; x++)
cout<< array[x];
return 0;
}
|
| theleprechaun is offline | |
| | #2 |
| Registered User Join Date: Dec 2006
Posts: 1,780
| You need to type in 8 values first (followed by [enter]s). Would probably be clearer if there was a prompt. |
| cyberfish is offline | |
| | #4 |
| Registered User Join Date: Aug 2008
Posts: 3
| The program prompts me for array input, and allows me to type in the 8 numbers, but then it exits, without printing them. So I would guess the problem is in the second If statement |
| theleprechaun is offline | |
| | #5 |
| Registered User Join Date: Dec 2006
Posts: 1,780
| The problem is not in the actual program. Read the FAQ entry. |
| cyberfish is offline | |
| | #6 |
| ∞ Join Date: May 2005
Posts: 962
| I have balls. Code: #include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int array[8];
for(int x=0; x<8; x++)
cin>> array[x];
for(int x=0; x<8; x++)
cout<< array[x];
getch();
return 0;
}
__________________ argus triad mingus |
| BobMcGee123 is offline | |
| | #7 |
| Registered User Join Date: Aug 2008
Posts: 3
| Ah, I see. Got it now, Thank you for the help. |
| theleprechaun is offline | |
![]() |
| Tags |
| array, code.completion, noob |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| A noob question - how to reduce the size of an array? | itachi | C Programming | 2 | 11-24-2005 01:30 AM |
| 2d array question | JoshR | C++ Programming | 5 | 04-09-2005 12:52 PM |
| linked list inside array of structs- Syntax question | rasmith1955 | C Programming | 14 | 02-28-2005 05:16 PM |
| Array of Structs question | WaterNut | C++ Programming | 10 | 07-02-2004 02:58 PM |
| End of Code Loop Question | JuanSverige | C++ Programming | 1 | 04-08-2003 10:35 AM |