#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
#include<fstream>


using namespace std;


int main()
{
	int num;

	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("random.dat");
	outFile.open ("randout");
	


bool seenBefore(int, int *);

    int seen[91];
    for(int i=0; i<91; i++)
    { // set all bools to false.
        seen[i]=false;
    }
    
    while ( inFile >> num ) 
	{
		outFile << "Your non-repitive #:"<<endl;
		
	}
    
    for (int i = 10; i<101; i++)
    { 
        cout << i << " " << seenBefore(i, seen) << "\n";// 0=not seen before, 1 = seen before.
    }
}

bool seenBefore(int num, int *seen)
{
     if(seen[num-10])
     {
         return true;
     }
     
     seen[num-10] = true;
     
	return 0;
}

----------------------------------------------------------------------------------
Ok....this is what i kinna figured...so couldn't I just let the program check the inFile(which contains the random #'s already) ?to see how much time they appear? But could I adjust this so that when each # is read from the inFile, print it only if it's not a duplicate of a number already read (and printed)?? Thx for all the assistance.

So why aren't you calling seenBefore() in the loop, as demonstrated in previous replies?

#include <iostream>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <string>
#include<fstream>


using namespace std;


int main()
{
	int num;

	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("random.dat");
	outFile.open ("randout");
	


bool seenBefore(int, int *);

    int seen[91];
    for(int i=0; i<91; i++)
    { // set all bools to false.
        seen[i]=false;
    }
    
    while ( inFile >> num ) 
	{
		{
		if ( !seenBefore(num) )
		}
	
	{
		outFile << "Your non-repitive #'s :"<<num<<endl;
	}
    
    for (int i = 10; i<101; i++)
    { 
        cout << i << " " << seenBefore(i, seen) << "\n";// 0=not seen before, 1 = seen before.
    }
}

bool seenBefore(int num, int *seen)
{
     if(seen[num-10])
     {
         return true;
     }
     
     seen[num-10] = true;
     
	return 0;
}

----------------------------------------------------------------------------------

Why am I receiving the following errors:
'seenBefore' : function does not take 1 arguments
syntax error : missing ';' before '}'
'seenBefore' : local function definitions are illegal

Why am I receiving the following errors:
'seenBefore' : function does not take 1 arguments

bool seenBefore(int, [B]int *[/B]);

syntax error : missing ';' before '}'

Depends on where the error is. This is why we ask you to post the exact error message, in full!

ok thx

1>------ Build started: Project: lab-6, Configuration: Debug Win32 ------
1>Compiling...
1>lab-6.cpp
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(44) : error C2660: 'seenBefore' : function does not take 1 arguments
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(45) : error C2143: syntax error : missing ';' before '}'
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(45) : warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(58) : error C2601: 'seenBefore' : local function definitions are illegal
1>        c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(17): this line contains a '{' which has not yet been matched
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(69) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(17)' was matched
1>Build log was saved at "file://c:\Users\Neil\Documents\Visual Studio 2005\Projects\lab-6\lab-6\Debug\BuildLog.htm"
1>lab-6 - 4 error(s), 1 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

bool seenBefore(int, int *);...how can i get it to work?

You seem to be just pressing keys randomly.

while ( inFile >> num ) {
  if ( !seenBefore(num,seen) ) {
    outFile << "Your non-repitive #'s :"<<num<<endl;
  }
}

oh...i see it now....but i still get:
1>------ Build started: Project: lab-6, Configuration: Debug Win32 ------
1>Compiling...
1>lab-6.cpp
1>c:\users\neil\documents\visual studio 2005\projects\lab-6\lab-6\lab-6.cpp(44) : error C2660: 'seenBefore' : function does not take 1 arguments

Sorry for taking so long to reply. My code is as below:

#include<iostream>
#include <string>
#include<fstream>


using namespace std;



int main()
{
	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("random.dat");
	outFile.open ("randout");

	int numbers[91]={0};
    int counter=0;
    int num=0;
    
    inFile>>num;
    while(num!=0)
    {
    bool found = false;
    for(int i=0;i<=counter;i++)
    {
            if(numbers[i]==num)
            {
               found=true;
               break;
            }
    }
    if(!found)
    {
        cout<<num<<" is a non repeating number."<<endl;
        numbers[counter++]=num;
    } 
    outFile<<" "<<endl;
    inFile>>num;

    }    
    return 0;

}

A couple things....
1. Does my use of "while(num!=0)" make a differnce in the programs ability to read in the 1000 numbers?
2. What's wrong with using a break in a 'for' loop and what difference will/does it make?
3. When i take out the line

cout<<num<<" is a non repeating number."<<endl;

...I get a buch on error messages...any reason why?

Thanks for assistance.

Also, would it be possible to use a while loop?

> ...I get a buch on error messages...any reason why?
Maybe post a few examples?

> 1. Does my use of "while(num!=0)" make a differnce in the programs ability to read in the 1000 numbers
It assumes there is a number 0 in the file. If there isn't, then bad things can happen. while ( inFile >> num ) will at least exit the loop if there is any sign of trouble, or the end of the file.

> 2. What's wrong with using a break in a 'for' loop and what difference will/does it make?
Depends how "pure" you want your code to be. Some people regard "break" as just another goto, and would write for(int i=0;i<=counter && !found;i++)

Below is my code: Why does it not print anything out? As you can see in my previous posts, i was using a wile loop, howver, my instructor said i can't use it.

#include<iostream>
#include <string>
#include<fstream>


using namespace std;



int main()
{
	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("random.dat");
	outFile.open ("randout");

	int numbers[91]={0};
    int counter=0;
    int num=0;
    
    inFile>>num;
    
    {
    bool found = false;
    for(int i=0;i<=counter;i++)
    {
            if(numbers[i]==num)
            {
               found=true;
             }
    }
    if(!found)
    {
		cout<<"These are the non-repeating #"<<endl;
        numbers[counter++]=num;
    } 
	inFile>>num;
     }    
    return 0;

}

Below is my code: Why does it not print anything out? As you can see in my previous posts, i was using a wile loop, howver, my instructor said i can't use it.

Comments point out problems:

#include<iostream>
#include <string>
#include<fstream>


using namespace std;



int main()
{
	
	ifstream inFile;
	ofstream outFile;

	inFile.open ("random.dat");
	outFile.open ("randout");

	int numbers[91]={0};
    int counter=0;
    int num=0;
    
    inFile>>num;
    
    {
    bool found = false;
    for(int i=0;i<=counter;i++)  // counter is 0, so i is always <= counter
    {
            if(numbers[i]==num)
            {
               found=true;
             }
    }

    //// after you get here
    //// 1) you never saver any index so you don't know which
    ////      numbers repeat
    //// 2) counter still has no value
    if(!found)
    {
		cout<<"These are the non-repeating #"<<endl;
        numbers[counter++]=num;
    } 
	inFile>>num;
        //// You just read a number, and exit the program

     }    
    return 0;

}

You need to break you program into steps.
1) Read all the data
2) Next, look for duplicates and remember them by setting a flag in another array. Use 2 nested loops.
3) Loop through the flag array for any non-set values, those are the non-repeating values

So I see 4 loops necessary

>>i was using a wile loop, howver, my instructor said i can't use it.

That seems a bit unusual. You need some way to know when to stop reading input. If you know exactly how many items that have to be evaluated, then you can use a for loop. If you don't know exactly how many items there are, then it's often easier to use a while loop in terms of syntax.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.