C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 08-22-2008, 07:47 PM   #1
Registered User
 
Join Date: Aug 2008
Posts: 3
Noob question! Code completion - Array challenge

Hello.
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;

}
Hope I've clarified enough
theleprechaun is offline   Reply With Quote
Old 08-22-2008, 07:54 PM   #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   Reply With Quote
Old 08-22-2008, 08:22 PM   #3
and the Hat of Ass
 
Join Date: Dec 2007
Posts: 730
FAQ entry
rags_to_riches is offline   Reply With Quote
Old 08-22-2008, 08:25 PM   #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   Reply With Quote
Old 08-22-2008, 08:27 PM   #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   Reply With Quote
Old 08-22-2008, 08:47 PM   #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;
}
now leave me alone. Seriously.
__________________
argus triad mingus
BobMcGee123 is offline   Reply With Quote
Old 08-22-2008, 08:58 PM   #7
Registered User
 
Join Date: Aug 2008
Posts: 3
Ah, I see. Got it now, Thank you for the help.
theleprechaun is offline   Reply With Quote
Reply

Tags
array, code.completion, noob

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 08:16 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22