| | |
I am trying to get this code to work. Please help.
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
I am trying to make the random generator fill my array with no duplicates. An diplay the in order but aslo first line to print array[0], then second line array[0] and array[1], so on and so on until it display all twenty on one line.
Pease help
Code tags added. It's code, not c, btw. -Narue
Pease help
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> #include <time.h> #include <stdio.h> void insert(int [], int); // function prototype bool AlreadyThere(int array[], int value, int index); // called [],asize,call from init_call int main() { int count; const int MAXNUM = 20; int id[MAXNUM]; int newcode; bool lookingForNew; srand(time(NULL)); for(count = 0; count<MAXNUM; count ++) { lookingForNew= true; while(lookingForNew) { newcode = 1.0 + (double)rand()/(double)(RAND_MAX + 1) * 50.0; //cout<<"x"<<newcode<<endl; //if(AlreadyThere(id,newcode,count)) if (id[count] == count || count == 0) { id[count]=newcode; lookingForNew = false; cout<<id[0]<<id[1]<<endl; } } } insert(id,newcode); return 0; } void insert(int idcode[], int newcode) { int i, newpos, trlpos; // find correct position to insert the new code i = 0; while (idcode[i] < newcode) i++; newpos = i; // found the position for the new code // find the end of the list while (idcode[i] != 51) i++; trlpos = i; // move idcodes over one position for (i = trlpos; i >= newpos; i--) idcode[i+1] = idcode[i]; // insert the new code idcode[newpos] = newcode; return; }
Okay, you've explained what you're trying to do and the code shows how you're going about it. However, you've neglected to tell us what you're code doesn't do that you want it to. I don't know about everyone else, but I don't have time to analyze every program that somebody posts here. I'll only answer a question if there's a precise explanation of what the problem is. Posting what you're trying to do and a bunch of code is only 2/3 of a proper question.
New members chased away this month: 5
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
The program won't run it keeps giving me errors:
error LNK2001: unresolved external symbol "bool __cdecl AlreadyThere(int * const,int,int)" (?AlreadyThere@@YA_NQAHHH@Z)
Debug/Program 4 LG.exe : fatal error LNK1120: 1 unresolved externals
I am not sure how to fix it. I think it has to with the function I names, but I am not sure what else to do.
Thanks,
lululg76
error LNK2001: unresolved external symbol "bool __cdecl AlreadyThere(int * const,int,int)" (?AlreadyThere@@YA_NQAHHH@Z)
Debug/Program 4 LG.exe : fatal error LNK1120: 1 unresolved externals
I am not sure how to fix it. I think it has to with the function I names, but I am not sure what else to do.
Thanks,
lululg76
>unresolved external symbol "bool __cdecl AlreadyThere(int * const,int,int)"
Well that's easy (sort of). Write the function. As it is, you declare it here:
But you never define the body.
Well that's easy (sort of). Write the function. As it is, you declare it here:
C++ Syntax (Toggle Plain Text)
bool AlreadyThere(int array[], int value, int index);
New members chased away this month: 5
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
I have gotten my AlreadyThereFuntcion to work. The random genertor is generationg random numbers. I just don't understand why the rest of my code isn't placing the numbers in order. I don't get any errors the display is just wrong.
any help is appreciated
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> #include <time.h> #include <stdio.h> void insert(int [], int); // function prototype bool AllReadyThere(int *array, int value, int index) { for(int j = 0; j < value; j++) if(array[j] == value) return true; return false; } int main() { int count; const int MAXNUM = 20; int id[MAXNUM]; int newcode; bool lookingForNew; srand(time(NULL)); for(count = 0; count<MAXNUM; count ++) { lookingForNew= true; while(lookingForNew) { newcode = 1.0 + (double)rand()/(double)(RAND_MAX + 1) * 50.0; //cout<<"x"<<newcode<<endl; if(!AllReadyThere(id,newcode,count)) { id[count]=newcode; lookingForNew = false; cout<<id[count]<<endl; } } } insert(id,newcode); AllReadyThere(int *array, int value, int index); return 0; } void insert(int idcode[], int newcode) { int i, newpos, trlpos; // find correct position to insert the new code i = 0; while (idcode[i] < newcode) i++; newpos = i; // found the position for the new code // find the end of the list while (idcode[i] != 51) i++; trlpos = i; // move idcodes over one position for (i = trlpos; i >= newpos; i--) idcode[i+1] = idcode[i]; // insert the new code idcode[newpos] = newcode; return; }
any help is appreciated
Read this please. I'm getting tired of fixing your attempts at code tags.
New members chased away this month: 5
•
•
Join Date: Apr 2005
Posts: 9
Reputation:
Solved Threads: 0
C++ Syntax (Toggle Plain Text)
#include <iostream.h> #include <stdlib.h> #include <time.h> #include <stdio.h> void insert(int [], int); // function prototype bool AllReadyThere(int *array, int value, int index) { for(int j = 0; j < value; j++) if(array[j] == value) return true; return false; } int main() { int count; const int MAXNUM = 20; int id[MAXNUM]; int newcode, moves; bool lookingForNew; srand(time(NULL)); for(count = 0; count<MAXNUM; count ++) { lookingForNew= true; while(lookingForNew) { newcode = 1.0 + (double)rand()/(double)(RAND_MAX + 1) * 50.0; //cout<<"x"<<newcode<<endl; if(!AllReadyThere(id,newcode,count)) { id[count]=newcode; lookingForNew = false; cout<<id[count]<<endl; } } } insert(id,newcode); return 0; } void insert(int idcode[], int newcode) { int i, newpos, trlpos; // find correct position to insert the new code i = 0; while (idcode[i] < newcode) i++; newpos = i; // found the position for the new code // find the end of the list while (idcode[i] != 51) i++; trlpos = i; // move idcodes over one position for (i = trlpos; i >= newpos; i--) idcode[i+1] = idcode[i]; // insert the new code idcode[newpos] = newcode; return; }
Could you help me. I can't figure out why the code after return 0; isn't putting the numbers in orders.
Thanks
![]() |
Similar Threads
- Why won't this code work? (VB.NET)
- The following Code won't work, Plez help? (C++)
- Why this code cant work ???? (ASP.NET)
- Source Code that don't work? (Java)
- Null Pointer? will this code work (C)
- beans bound property: getNewValue() doesn't work out. Code attached (Java)
Other Threads in the C++ Forum
- Previous Thread: Linefeed problem at the end of a record
- Next Thread: C++ tips
Views: 2372 | Replies: 6
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment based beginner binary c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg search sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






