In this program i am trying to find numbers that are multiples of 7,11, or 13,
also if the total of the numbers is even or odd
also the square root value of each number
also if there are any prime numbers in the list

#include<iostream>
#include<iomanip>
#include<fstream>
#include<cmath>
#include<conio.h>
// Associating program identifiers with external file names
#define in_file "data.txt"//input file name
#define out_file "result.txt"//output file name

using namespace std;

void multiple(int);
void even_odd(int);
void square_root(double);
void prime(int);

int temp_a;
double temp_c;
int total;
int num;
ifstream ins;// associates ins as an input stream
ofstream outs;// associates outs as an output stream

int main()
{

    ins.open(in_file);// associates ins as an input stream
    outs.open(out_file);// associates outs as an output stream
   
    multiple(temp_a);
    even_odd(total);
    square_root(temp_c);
    prime(num);
   
    ins.close();// closing input file
    outs.close();// closing output file

    return 0;
}

void multiple(int temp_a)//function to find multiples(7, 11, 13)
{
    int a=7;
    int b=11;
    int c=13;
    int m7, m11, m13;

    while(!ins.eof())
    {
        ins>>temp_a;
        if(temp_a>-1)
        {
        m7=temp_a%a;
        m11=temp_a%b;
        m13=temp_a%c;
        if((m7==0)&&(m11!=0)&&(m13!=0))
            outs<<temp_a<<" is a multiple of 7."<<endl;
        else if((m11==0)&&(m7!=0)&&(m13!=0))
            outs<<temp_a<<" is a multiple of 11."<<endl;
        else if((m13==0)&&(m11!=0)&&(m7!=0))
            outs<<temp_a<<" is a multiple of 13."<<endl;
        else if((m7==0)&&(m11==0)&&(m13!=0))
            outs<<temp_a<<" is a multiple of 7 and 11."<<endl;
        else if((m11==0)&&(m13==0)&&(m7!=0))
            outs<<temp_a<<" is a multiple of 11 and 13."<<endl;
        else if((m7==0)&&(m13==0)&&(m11!=0))
            outs<<temp_a<<" is a multiple of 7 and 13."<<endl;
        else if((m7==0)&&(m11==0)&&(m13==0))
            outs<<temp_a<<" is a multiple of 7, 11, and 13."<<endl;
        else
            outs<<temp_a<<" is not a multiple of 7, 11, or 13."<<endl;
        }
        ins>>temp_a;
    }
    outs<<endl;
}

//problem with this function!!!!!
void even_odd(int total)//function to find it total is even or odd
{
    int p;
    while(!ins.eof())
    {
        ins>>total;
        total+=total;
    }
    cout<<total<<endl;
        p=total%2;
        if(p==0)
            outs<<"Even"<<endl;
        else
            outs<<"Odd"<<endl;
   
        getch();
}



void square_root(double temp_c)//function to find square root
{
    while(!ins.eof())
    {
        ins>>temp_c;   
        if(temp_c>0)
            outs<<sqrt(temp_c)<<endl;
    }
}

void prime(int num)//function t find prime numbers
{
    while(!ins.eof())
    {
        ins>>num;
        bool isPrime=true;
        for ( int j = 2; j <num; j++)
                {
                        if ( num % j == 0 )
                        {
                          isPrime=false;
                          break;
                        }
                }
                if (isPrime)
                {
                  outs<<num<<" is a prime number."<<endl;
                }
                isPrime=true;   
    }
}

the only function that isnt working propery is the void even_odd() function, i dont know whats wrong with it, its pretty simple so how is it messing up??
another problem is that it will do everytihng for the first function properly, but it doesnt start doing everytihng for the next function? it should do all the steps in void multiple then move on to the next function, but its not, and i tihnk im just missing someithng to make it do that but im not sure what it is because i ahve no idea what to look for or whats its called?

forgot to mention that these are the numbers im using for input:

104
3773
13
121
77
30751

ok well i seem to have gotten the void even_odd funtion working, so now the only problem is getting all the functions to execute

ok well i seem to have gotten the void even_odd funtion working, so now the only problem is getting all the functions to execute

i think it only doesnt work because the file doesnt read in agian, but how do i make it so that it reads in the numbers from file all over again each time???

thanks for the help guys!!! :l

basically i put ins.open(in_file); at the beginning of every function and
ins.close(); at the end but i also used ins.clear();

like this:

void square_root(double temp_c)//function to find square root
{
	ins.open(in_file);// associates ins as an input stream
    while(!ins.eof())
    {
        ins>>temp_c;   
        if(temp_c>0)
            outs<<sqrt(temp_c)<<endl;
    }
	ins.clear();
	 ins.close();// closing input file
    
}

so ya now it works fine

An alternative might be to read them in main into a vector and pass the address of the vector to the functions as a second argument.

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.