GIDForums  

Go Back   GIDForums > Computer Programming Forums > C++ Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 27-Jun-2005, 17:29
rho rho is offline
New Member
 
Join Date: Jun 2005
Posts: 12
rho is on a distinguished road

Need help with Simple 1D Array coding project


Hello out there. i have a c++ project dealing with simple 1D arrays. I am wondering if there is anyone out there willing to help me out because the project is due tomorrow as well as my final exam for a intro to c++ class. i am in the same EXACT situation as harleyrider, if anyone has seen his thread. same class, same project. decided to come on here myself to seek help. first of all, i would like to clarify our project. BASICALLY:
the project requires that we make two simple 1D arrays.

1) the first will hold numbers from 1 -> a number the user inputs, in inremental order.
2) in the first array, a counter should count, starting from 1, three spots, then remove that number from the list, and dump it into a second array. and then it should continue counting from the next number till it hits the third spot from there. it should repeat this cycle until there is one number left. to clarify, here's an example:

123456 initial list of numbers, start counting from 1

12456 number 3 is eliminated, dump into second array
continue counting from 4

1245 suitor 6 eliminated, dump into second array
continue counting from 1

125 suitor 4 eliminated, dump into second array
continue counting from 5

15 suitor 2 eliminated, dump into second array
continue counting from 5

1 suitor 5 eliminated, dump into second array
1 is the lucky winner

my problem is i have basically no idea where to start. i have sribbled down some code. but i don't know how to:

1) get every third number:
2) input every third number into second array
3) display output exactly like the example above

CPP / C++ / C Code:
#include <iostream>
#include <iomanip>

using namespace std;


int main()
{
int winnerArray[61];
int loserArray[60];
int numOfSuitors = 0;
int i;
int j = 0;
int counter = 0;

cout << "Enter the number of suitors: " << endl;
cin  >> numOfSuitors;
cout << '\n';

for(i = 0; i <numOfSuitors; i++)
{
	winnerArray[i] = i+1;
	cout << winnerArray[i] << " " ;
}

cout << "initial list of suitors, start counting from 1" << endl;
cout << '\n' << '\n';

//from here on i'm just writing stuff to try out. it's supposed to be how the program takes every third number, removes it and dumps it into a second array. 

if(winnerArray[i] == 0)
{
    counter++;
}

if (counter % 3 == 0)
{
    loserArray[j] = winnerArray[i];
    winnerArray[i]= 0;
    j++;
}

cout << loserArray[j];

return 0;
}



thank you for your time and help
  #2  
Old 27-Jun-2005, 19:01
WaltP's Avatar
WaltP WaltP is offline
Outstanding Member
 
Join Date: Feb 2004
Location: Midwest US
Posts: 3,234
WaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to allWaltP is a name known to all
Deja vu! :-D

Code:
1) create 2 values to be pointers into the 2 arrays. 2) start a loop that ends only when there is one value left in the first array. 3) skip 3 positions a) increment the first pointer 3 times b) if at any time the pointer reaches the end of the array, reset it to 0 4) Copy the current position into the second array. 5) Another loop: a) Move the next value into the current value replacing it. b) Continue until you hit the end of the array (this moves all the entries down, filling the hole. Your array size changes at this point.)
__________________

Cow: You're a lawyer too?
Mooseblood (mosquito): Ma'am, I was already a bloodsucking parasite. All I needed was a briefcase!
  #3  
Old 27-Jun-2005, 19:05
rho rho is offline
New Member
 
Join Date: Jun 2005
Posts: 12
rho is on a distinguished road
thank you so much for helping me walt. however, i should probably have said that i'm not allowed to use pointers or new/delete, as we have not covered that in class. is there a i guess i should say "dumber" way around it. the only thing i'm positive i have, is that i'm able to set the first array, winnerArray, with numbers incrementing in order from 1 and up, with the max number = to the number the user inputs. but i have no idea as how the loop would work for taking out every third number, removing it and dumpin it into a second array. also, once the count reaches the end of the first array, it must continue counting to the beginning of the array. i don't know how to do that either?
 
 

Recent GIDBlogFlickr uploads of IA pictures by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Sorting Algorithms by Time silicon C++ Forum 4 02-May-2005 21:54
template comiling problems - need expert debugger! crq C++ Forum 1 01-Feb-2005 21:26
more array help (simulation project..) dilmv C++ Forum 6 17-Oct-2004 07:51
Need help on simple Programming Project daNichex6 C Programming Language 1 03-Sep-2004 18:08

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 21:05.


vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.