|
|
| Author |
Message |
Renork
RealPoor Master of Posts

Joined: 23 Jun 2003 Posts: 6282
|
Posted: 06/09/05 - 15:08 Post subject: Anyone take a look at this C++ code?
|
|
|
Can anyone tell me what im doing wrong in here?
| Code: | #include <iostream>
#include <ctime>
using namespace std;
int main()
{
void printresults( int [] );
void dan(int []);
int i,t=0,choice,myarr[10],count[50];
srand((unsigned)time(NULL));
for(i=0; i<10; i++)
{
choice = rand()%10+1;
myarr[i] = choice;
}
dan(count);
cout << "And the array was " << endl;
printresults(myarr);
return 0;
}
void printresults(int myarr[])
{
for(int i=0; i<10; i++)
cout << myarr[i] << " "<<endl;
}
void dan(int count[],myarr[]) // getting error C2061: syntax error : identifier 'myarr'
{
int t=0;
if(myarr[t]==count[t]) // getting error C2065: 'myarr' : undeclared identifier
count[t]++;
cout << t+1 << "'s = " << count[t] << endl;
t++;
}
|
|
|
|
Back to top
|
|
|
|
 |
Manuva
Banned

Joined: 12 Oct 2002 Posts: 2536
|
Posted: 06/09/05 - 15:10 Post subject:
|
|
|
I can see now what you're doing wrong.
You're not having your roomate strangle you to death while you try and write it.
|
|
|
Back to top
|
|
|
|
 |
Kikk
Can't Stop Posting

Joined: 14 Oct 2002 Posts: 695
Location: Jacksonville, NC
|
Posted: 06/09/05 - 15:16 Post subject:
|
|
|
Not a C, C++ programmer but when you are calling the function dan you are only passing count but yet you have the function defined to accept two params.
for(i=0; i<10; i++)
{
choice = rand()%10+1;
myarr[i] = choice;
}
dan(count);
|
|
|
Back to top
|
|
|
|
 |
Occulis
RealPoor Jedi

Joined: 11 Oct 2002 Posts: 13293
Location: Moral Relativity Central
|
Posted: 06/09/05 - 15:18 Post subject: Re: Anyone take a look at this C++ code?
|
|
|
| Renork wrote: |
| Code: |
void dan(int count[],myarr[]) // getting error C2061: syntax error : identifier 'myarr'
|
|
That means it doesn't know what myarr is. Review function and variable declarations. Every variable needs a type, so...:
| Code: |
void dan(int *count, int *myarr) {
*count += (*myarr) * 666;
}
|
|
|
|
Back to top
|
|
|
|
 |
Renork
RealPoor Master of Posts

Joined: 23 Jun 2003 Posts: 6282
|
Posted: 06/09/05 - 15:20 Post subject:
|
|
|
thanks guys, Owynn sugested I make the arrays global and that worked fine.
its working, I just dont have it all set correctly to do what it is suposed to yet.
this is what I need it to do...
Write a c++ program that flips a 10 sided 'coin' 1000 times (im just testing it at 10 atm, easier to check if its working, will add the extra 0's once it is). your program will output the number of times each 'side' appears. Your program needs to use an array to store each flip of the coin. Your program later should analyze the data stored in the array to acheive the final output.
|
|
|
Back to top
|
|
|
|
 |
|
|