i got that to work now , but now my functions are repeating even though i have the while (!ins.eof())
, sorry im very new to programming , here is what im outputting now:
The square root of 104 is 10.198
The square root of 3773 is 61.4248
The square root of 13 is 3.60555
The square root of 121 is 11
The square root of 77 is 8.77496
The square root of 30751 is 175.36
104 is a multiple of 13
3773 is a multiple of 7
13 is a multiple of 13
121 is a multiple of 11
77 is a multiple of 7
30751 is a multiple of 7
104 is even
3773 is odd
13 is odd
121 is odd
77 is odd
30751 is odd
The square root of 104 is 10.198
The square root of 3773 is 61.4248
The square root of 13 is 3.60555
The square root of 121 is 11
The square root of 77 is 8.77496
The square root of 30751 is 175.36
104 is a multiple of 13
3773 is a multiple of 7
13 is a multiple of 13
121 is a multiple of 11
77 is a multiple of 7
30751 is a multiple of 7
104 is even
3773 is odd
13 is odd
121 is odd
77 is odd
30751 is odd
The square root of 104 is 10.198
The square root of 3773 is 61.4248
The square root of 13 is 3.60555
The square root of 121 is 11
The square root of 77 is 8.77496
The square root of 30751 is 175.36
-858993460 is a multiple of 13
-858993460 is even
-858993460 is a multiple of 13
-858993460 is even
The square root of -9.25596e+061 is -9.25596e+061
-858993460 is a multiple of 13
-858993460 is even
The square root of 104 is 10.198
The square root of 3773 is 61.4248
The square root of 13 is 3.60555
The square root of 121 is 11
The square root of 77 is 8.77496
The square root of 30751 is 175.36
104 is a multiple of 13
3773 is a multiple of 7
13 is a multiple of 13
121 is a multiple of 11
77 is a multiple of 7
30751 is a multiple of 7
104 is even
3773 is odd
13 is odd
121 is odd
77 is odd
30751 is odd
The square root of 104 is 10.198
The square root of 3773 is 61.4248
The square root of 13 is 3.60555
The square root of 121 is 11
The square root of 77 is 8.77496
The square root of 30751 is 175.36
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include<iostream>
#include<conio.h>
#include<fstream>
#include<iomanip>
#include<cmath>
#define in_file "data.txt"
#define out_file "result.txt"
using namespace std;
void multiples();
void oddoreven();
void squareroot();
int main ()
{
multiples();
oddoreven();
squareroot();
} // end main
void multiples() // function deinition
{
ifstream ins;
std::ofstream ofs ("result.txt", std::ofstream::app);
ins.open (in_file);
int number;
while (!ins.eof())
{
ins >> number;
if (number % 7 == 0)
ofs << number << " is a multiple of 7" << endl;
else if (number % 11 == 0)
ofs << number << " is a multiple of 11" << endl;
else if (number % 13 == 0)
ofs << number << " is a multiple of 13" << endl;
}
}
void oddoreven () // function definition
{
ifstream ins;
std::ofstream ofs ("result.txt", std::ofstream::app);
ins.open (in_file);
int number;
while (!ins.eof())
{
ins >> number;
if ( number % 2 == 0 )
ofs << number << " is even " << endl;
else if (number % 2 == 1 )
ofs << number << " is odd " << endl;
}
}
void squareroot () // function definition
{
ifstream ins;
std::ofstream ofs ("result.txt", std::ofstream::app);
ins.open (in_file);
double number;
double result;
while (!ins.eof())
{
ins >> number;
if ( number > 0 )
result = sqrt(number);
ofs << "The square root of " << number << " is " << result << endl;
}
}
|