67 lines
1.4 KiB
C++
67 lines
1.4 KiB
C++
#include <iostream>
|
|
#include <map>
|
|
#include <vector>
|
|
#include <cmath>
|
|
#include "Element.h"
|
|
using namespace std;
|
|
|
|
|
|
// For now just a list with elements and their atomic weight
|
|
|
|
|
|
|
|
|
|
|
|
|
|
double integer_maker(const vector<double>& coefs) {
|
|
cout << "Started Integer Maker" << endl;
|
|
int i = 1;
|
|
bool isGood = false;
|
|
for(auto &x : coefs) {
|
|
cout << "Initial check if ints" << endl;
|
|
double intpart = 0.0;
|
|
if(modf(x, &intpart) != 0.0) {
|
|
isGood = false;
|
|
break;
|
|
}
|
|
isGood = true;
|
|
}
|
|
|
|
|
|
if(!isGood) {
|
|
cout << "So they're not ints. Starting algorithm to intinize them" << endl;
|
|
for (i = 2; (i < 9999999) && !isGood; i++) {
|
|
cout << "Outer loop for i=" << i << endl;
|
|
for (auto x: coefs) {
|
|
cout << "Running thru coefs for coef: " << x << endl;
|
|
double y = x;
|
|
double intpart;
|
|
//cout << "y * i: " << y << " " << i << " " << " = " << y*i << endl;
|
|
double d_val = ceil(modf(y * i, &intpart) * 10) / 10;
|
|
cout << "d_val: " << d_val <<endl;
|
|
if((d_val != 0.0) && (d_val+0.1 != 0.0) && (d_val-0.1 != 0.0) &&
|
|
(d_val != 1) && (d_val+0.1 != 1) && (d_val-0.1 != 1)) {
|
|
isGood = false;
|
|
break;
|
|
}
|
|
isGood = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
return i-1;
|
|
}
|
|
|
|
|
|
int main() {
|
|
map<string, double> elms = { {"C", 49.3}, {"H", 6.9}, {"O", 43.8} };
|
|
//Element::find_empirical(elms);
|
|
|
|
vector<double> nums = {1, 2.33};
|
|
|
|
cout << integer_maker(nums) << endl;
|
|
|
|
return 0;
|
|
}
|