while loop not showing expected result

I made a switch from win to fedora, set everything up properly, but now my code no longer works....it compiles but instead of a number(a double) i get inf
on mvs2013 it worked , but now in fedora it doesn't

i use geany:
compile: g++ -Wall -std=c++14 -c "%f"
build: g++ -Wall -std=c++14 -o "%e" "%f"

i input 2 numbers let's say n=20 and ngr=17(this is all my input for this program)

a lot happens

i need to get a value that meets the epsilonTGsec condition through iteration

!note: i know the values with which to begin the rest i put in loop
i cannot see what is wrong :(

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
double iGprim = retGprim.iG;
double cGmsecund_Stelat = retGprim.cGm;
double iGsecund_Stelat = iGprim - (DaN / (nr*DgN));
		
std::vector<double> cGmsecundStelat={ cGmsecund_Stelat };
std::vector<double> iGsecundStelat={ iGsecund_Stelat };
std::vector<double> tGsecundStelat;

double epsilonTGsec{100}; int interTG{0};

while (epsilonTGsec >= 0.01){
double tGInt = iGsecundStelat[interTG] / cGmsecundStelat[interTG];
tGsecundStelat.emplace_back(tGInt);
double cGmInt =InterpolareCalduraSpecificaGaze(tGsecundStelat[interTG], compozitiaG);
cGmsecundStelat.emplace_back(cGmInt);			
double iGsec = cGmsecundStelat[interTG] * tGsecundStelat[interTG-1];
iGsecundStelat.emplace_back(iGsec);
double epsilonabs=iGsecundStelat[interTG] - iGsecundStelat[interTG - 1];
epsilonTGsec = (abs(epsilonabs) / iGsecundStelat[interTG - 1]);
if (epsilonTGsec < 0.01){
	double tGsec= tGsecundStelat[interTG];
	std::cout << "tGsecund = " << tGsec << " grade C\n";
	}
	else interTG++;
}
		
There's a bunch of names being referenced which haven't been defined anywhere. Code like that is meaningless, just post the entire thing, or a minimum portion that reproduces the issue.
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
#include "iostream"
#include "vector"
#include "stdio.h"
#include "string"
#include "limits"
#include "cstdlib"

class Bad_input {};//for error handling


inline double InterpolareCalduraSpecificaGaze(double tempgc, std::vector<double> compgc){
	std::vector<double> temp = { 600, 700, 800, 900, 1000 };
	std::vector<double> CO2 = { 2.041, 2.088, 2.131, 2.169, 2.204 };
	std::vector<double> O2 = { 1.417, 1.434, 1.45, 1.465, 1.478 };
	std::vector<double> H2O = { 1.61, 1.64, 1.67, 1.695, 1.72 };
	std::vector<double> CO = { 1.357, 1.372, 1.386, 1.4, 1.413 };
	std::vector<double> N2 = { 1.345, 1.359, 1.372, 1.385, 1.397 };
	int i{ -1 };
	double retvalue{ -1 };

	if (tempgc>600 && tempgc < 700) i = 0;
	if (tempgc>700 && tempgc < 800) i = 1;
	if (tempgc>800 && tempgc < 900) i = 2;
	if (tempgc>900 && tempgc < 1000) i = 3;

	double cgmCO2 = ((tempgc - temp[i]) / (temp[i + 1] - temp[i]))*(CO2[i + 1] - CO2[i]) + CO2[i];
	double cgmO2 = ((tempgc - temp[i]) / (temp[i + 1] - temp[i]))*(O2[i + 1] - O2[i]) + O2[i];
	double cgmH2O = ((tempgc - temp[i]) / (temp[i + 1] - temp[i]))*(H2O[i + 1] - H2O[i]) + H2O[i];
	double cgmCO = ((tempgc - temp[i]) / (temp[i + 1] - temp[i]))*(CO[i + 1] - CO[i]) + CO[i];
	double cgmN2 = ((tempgc - temp[i]) / (temp[i + 1] - temp[i]))*(N2[i + 1] - N2[i]) + N2[i];

	//std::vector<double> compozitiaG = { rCO2, rO2, rH2O, rCO, rN2 } =compg
	std::vector<double> cgm = { cgmCO2, cgmO2, cgmH2O, cgmCO, cgmN2 };
	//r este in procente => impartim retvalue cu 100
	retvalue = ((cgm[0] * compgc[0]) + (cgm[1] * compgc[1]) + (cgm[2] * compgc[2]) + (cgm[3] * compgc[3]) + (cgm[4] * compgc[4])) / 100;

	return retvalue;
}

class ProprietatiGaze{
public:
	double cGm;
	double iG;
	double densitateGN;
	double densitateG;
	double lambdaG;
	double etaG;
	double niuG;
	double aG;
	double PrG;
}; 
ProprietatiGaze PropG(double tempg, std::vector<double> compg){
	//std::vector<double> compozitiaG = { rCO2, rO2, rH2O, rCO, rN2 } =compg

	ProprietatiGaze retg;

	//entalpia
	retg.cGm = InterpolareCalduraSpecificaGaze(tempg, compg);
	retg.iG = retg.cGm*tempg;

	//densitate la starea normala
	std::vector<double> roN = { 1.9748, 1.4289, 0.8036, 1.25, 1.2505 };
	retg.densitateGN = ((roN[0] * compg[0]) + (roN[1] * compg[1]) + (roN[2] * compg[2]) + (roN[3] * compg[3]) + (roN[4] * compg[4]))/100;

	//densitatea la o temperatura oarecare:
	retg.densitateG = retg.densitateGN*(273.15 / (tempg + 273.15));
	//vascozitate cinematica
	retg.etaG = InterpolareEtaGaze(tempg, compg);
	retg.niuG = retg.etaG / retg.densitateG;
	//difuzivtatea termica a aerului
	retg.lambdaG = InterpolareLambdaGaze(tempg, compg);
	retg.aG = (retg.lambdaG / (retg.densitateG*retg.cGm))*retg.densitateGN;
	//Prandtl pentru aer
	retg.PrG = retg.niuG / retg.aG;
	//return

	return retg;
}
Last edited on
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
int main(int argc, char* argv[])
{

	try
	{
		int nint{ 0 }; int ngrint{ 0 };
		double nr{ 0.97 };
		bool WarnCondition{ true };

		//warning
		while (WarnCondition == true){
			std::cout << "Atentie!!!!!\n\nAcest program nu contine notatiile corecte, scopul este de a face calculele! Desi notatiile sunt asemanatoare e de recomandat sa va referiti la materialele de la seminar pentru a nu avea probleme.\n";
			std::cout << "\n\nPentru a continua introduceti ok!\n> ";
			std::string TypedCondition("something");
			std::string Condition("ok");
			std::cin >> TypedCondition;
			if (TypedCondition.compare(Condition) == 0)  {
				std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
				std::cout << "\n\n\n\n\n\n\n\n";
				WarnCondition = false;
			}
			else std::cout << ">";
		}

		//
		//start
		//
		std::cout << "n catalog = "; std::cin >> nint;
		if (nint <= 0 || nint > 50) throw Bad_input{};//in case of nint different than expected range
		std::cout << "n grupa = "; std::cin >> ngrint;
		if (ngrint <= 0 || ngrint > 50) throw Bad_input{};//in case of ngrint different than expected range
		std::cout << "\n\n";
		double n = nint; double ngr = ngrint;

		//
		//Etapa 0: Date initiale
		//

		std::cout << "Proiectarea unui recuperator de caldura de tip clepsidra\n\n";

		std::cout << "Date initiale:";
		std::cout << "\n\n";

		std::cout << "Sa se proiecteze un recuperator de caldura de tip clepsidra pentru care se cunosc:\n\n";
		//a
		std::cout << "a) debitul de aer raportat la starea normala:\n";
		double DaN = 340 + 9 * n;
		std::cout << "DaN = " << DaN << " m3N/h\n\n";
		//b
		std::cout << "b) debitul de gaze la starea normala:\n";
		double DgN = 300 + 10 * n;
		std::cout << "DgN = " << DgN << " m3N/h\n\n";
		//c
		std::cout << "c) temperatura aerului la intrare:\n";
		double tAprim = 15 + ngr / 2;
		std::cout << "tAprim = " << tAprim << " grade C\n\n";
		//d
		std::cout << "d) temperatura aerului la iesire\n";
		double tAsecund = 200 - ngr / 2 + 2 * n;
		std::cout << "tAsecund = " << tAsecund << " grade C\n\n";
		//e
		std::cout << "e) temperatura gazelor la intrare:\n";
		double tGprim = 900 - 2 * n;
		std::cout << "tGprim = " << tGprim << " grade C\n\n";
		//f
		std::cout << "f) compozitia gazelor de ardere [%]:\n";
		double rCO2 = 4 + n / 5; double rO2 = 8 - n / 10; double rH2O = 13 - n / 10; double rCO = n / 20; double rN2 = 75 - n / 20;
		double rVerif = rCO2 + rO2 + rH2O + rCO + rN2;
		std::cout << "rCO2 = " << rCO2 << "\n";
		std::cout << "rO2 = " << rO2 << "\n";
		std::cout << "rH2O = " << rH2O << "\n";
		std::cout << "rCO = " << rCO << "\n";
		std::cout << "rN2 = " << rN2 << "\n\n";
		std::cout << "Verificare: " << rVerif << " (100 = OK)\n\n";
		std::vector<double> compozitiaG = { rCO2, rO2, rH2O, rCO, rN2 };
		//g
		std::cout << "g) coeficientul de retinere a caldurii: " << "nr = " << nr << "\n\n";
		//h
		std::cout << "h) viteza aerului in conditii normale prin tevi:\n";
		double wA1N = 15;
		std::cout << "wA1N = " << wA1N << " m/s\n\n";
		//i
		std::cout << "i) viteza aerului in conditii normale in spatiul inelar:\n";
		double wA2N = 10;
		std::cout << "wA2N = " << wA2N << " m/s\n\n";
		//j
		std::cout << "j) viteza gazelor in conditi normale:\n";
		double wGN = 0.8;
		std::cout << "wGN = " << wGN << " m/s\n\n";
		//k
		std::cout << "k) diametrul exterior al tevilor interioare:\n";
		double de = 0.04;
		std::cout << "de = " << de << " m\n\n";
		//l
		std::cout << "l) grosimea peretelui tevilor interioare:\n";
		double deltap = 0.5;
		double deltapm = deltap / 1000;
		std::cout << "deltap = " << deltap << " mm\n" << "deltapm = " << deltapm << " m\n\n";
		//m
		std::cout << "m) conductivitatea termica a peretelui:\n";
		double lambdap = 40;
		std::cout << "lambdap = " << lambdap << " W/mk\n\n";
		//n
		std::cout << "diametrul interior al tevilor interioare:\n";
		double di = de - 2 * deltap / 1000;
		std::cout << "di = " << di << " m\n\n";
		//o
		std::cout << "o) grosimea virolei interioare/exterioare:\n";
		double delta = 0.005;
		std::cout << "delta = " << delta << " m\n";
		std::cout << "\n\n\n";
		
Last edited on
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
//B proprietati gaze
		ProprietatiGaze retGprim = PropG(tGprim, compozitiaG);

		std::cout << "Pentru temperatura gazelor la intrare tGprim = " << tGprim << " grade C:\n\n";
		//caldura specifica la presiune constanta
		std::cout << " Caldura specifica la presiune constanta:\n";
		std::cout << "cGprim = " << retGprim.cGm << " kJ/m3N*K\n\n";

		//entalpia gazelor
		std::cout << " Entalpia gazelor:\n";
		std::cout << "iGprim = " << retGprim.iG << " kJ/m3N\n\n";

		//densitatea gazelor la o temperatura oarecare(reala:)
		std::cout << " Densitatea gazelor la starea nomala:\n";
		std::cout << "roGN = " << retGprim.densitateGN << " kg/m3N\n\n";
		std::cout << " Densitatea gazelor la o temperatura oarecare(reala):\n";
		std::cout << "roGprim = " << retGprim.densitateG << " kg/m3\n\n";

		//conductivitate termica
		std::cout << " Conductivitate termica:\n";
		std::cout << "lamnbdaGprim = " << retGprim.lambdaG << " *10^-3 W/m*K\n\n";

		//vascozitatea dinamica 
		std::cout << " Vascozitatea dinamica:\n";
		std::cout << "etaGprim = " << retGprim.etaG << " *10^-6 Pa*s\n\n";

		//vascozitatea cinematica
		std::cout << " Vascozitatea cinematica:\n";
		std::cout << "niuGprim = " << retGprim.niuG << " *10^-6 m2/s\n\n";

		//difuzivitatea termica
		std::cout << " Difuzivitatea termica:\n";
		std::cout << "aGprim = " << retGprim.aG << " *10^-6 m2/s\n\n";

		//nr prandtl
		std::cout << " Numarul Prandtl:\n";
		std::cout << "PrGprim = " << retGprim.PrG;
		std::cout << "\n\n\n\n";


		//
		//Etapa 2
		//

		std::cout << "Pentru temperatura gazelor la iesire: \n\n";  //interpolare si iteratie

		std::cout << "Din ecuatia bilantului termic se determina entalpia gazelor la iesire: iGsecundStelat=iGprim - QA/(randr*(DGN/3600)) [kJ'm3N]\n";
		std::cout << "Se initializeaza caldura specifica medie a gazelor la iesire cu valoarea corespunzatoare intrarii in recuperator cGmsecund = cGmprim [kJ/m3N]\n";

	    //incepe interpolarea pt tGsecund
		double iGprim = retGprim.iG;
		double cGmsecund_Stelat = retGprim.cGm;
		double iGsecund_Stelat = iGprim - (DaN / (nr*DgN));
		
		std::vector<double> cGmsecundStelat={ cGmsecund_Stelat };
		std::vector<double> iGsecundStelat={ iGsecund_Stelat };
		std::vector<double> tGsecundStelat;

		 //initialise i with 0 so that it starts with the already known variable since we cant to find temp[i=1] knowing ig[i=0] and cgm[i=0] from formula tg=ig/cgm
		double epsilonTGsec{100}; int interTG{0};
		while (epsilonTGsec >= 0.01){
			double tGInt = iGsecundStelat[interTG] / cGmsecundStelat[interTG];
			tGsecundStelat.emplace_back(tGInt);
			double cGmInt = InterpolareCalduraSpecificaGaze(tGsecundStelat[interTG], compozitiaG);
		    cGmsecundStelat.emplace_back(cGmInt);			
			double iGsec = cGmsecundStelat[interTG] * tGsecundStelat[interTG-1];
			iGsecundStelat.emplace_back(iGsec);
			double epsilonabs=iGsecundStelat[interTG] - iGsecundStelat[interTG - 1];
			epsilonTGsec = (abs(epsilonabs) / iGsecundStelat[interTG - 1]);
			if (epsilonTGsec < 0.01){
				double tGsec= tGsecundStelat[interTG];
				std::cout << "tGsecund = " << tGsec << " grade C\n";
			}
			else interTG++;
		}
		








		//end	
		std::cout << "\n\n\n\n";
		keep_window_open();
		return 0;
	}
	catch (Bad_input)
	{
		std::cerr << "\n\nERROR:  n poate lua doar valori intregi de la 1 la 50!!\n\n";
		keep_window_open();
		return 2;
	}
}


that should be all, it is console if that needed be mentioned..
Hi,

i use geany:
compile: g++ -Wall -std=c++14 -c "%f"
build: g++ -Wall -std=c++14 -o "%e" "%f"


You should set the level of the warnings high:

g++ -std=c++14 -Wall -Wextra -pedantic-errors -c "%f"

Do you have any warnings / errors when you compile using that?

Consider using a debugger if it is a runtime error.

Edit: It's worth reading the compiler manual, there are some other handy warnings that are still not enabled using those options.
Last edited on
-Wswitch-default
Warn whenever a switch statement does not have a default case.
-Wswitch-enum
Warn whenever a switch statement has an index of enumerated type and lacks a case for one or more of the named codes of that enumeration. case labels outside the enumeration range also provoke warnings when this option is used. The only difference between -Wswitch and this option is that this option gives a warning about an omitted enumeration code even if there is a default label.
-Wuninitialized
Warn if an automatic variable is used without first being initialized or if a variable may be clobbered by a setjmp call. In C++, warn if a non-static reference or non-static const member appears in a class without constructors.

If you want to warn about code that uses the uninitialized value of the variable in its own initializer, use the -Winit-self option.

These warnings occur for individual uninitialized or clobbered elements of structure, union or array variables as well as for variables that are uninitialized or clobbered as a whole. They do not occur for variables or elements declared volatile. Because these warnings depend on optimization, the exact variables or elements for which there are warnings depends on the precise optimization options and version of GCC used.

Note that there may be no warning about a variable that is used only to compute a value that itself is never used, because such computations may be deleted by data flow analysis before the warnings are printed.

-Wsuggest-override
Warn about overriding virtual functions that are not marked with the override keyword.

-Wfloat-equal
Warn if floating-point values are used in equality comparisons.

The idea behind this is that sometimes it is convenient (for the programmer) to consider floating-point values as approximations to infinitely precise real numbers. If you are doing this, then you need to compute (by analyzing the code, or in some other way) the maximum or likely maximum error that the computation introduces, and allow for it when performing comparisons (and when producing output, but that's a different problem). In particular, instead of testing for equality, you should check to see whether the two values have ranges that overlap; and this is done with the relational operators, so equality comparisons are probably mistaken.

-Wconversion
Warn for implicit conversions that may alter a value. This includes conversions between real and integer, like abs (x) when x is double; conversions between signed and unsigned, like unsigned ui = -1; and conversions to smaller types, like sqrtf (M_PI). Do not warn for explicit casts like abs ((int) x) and ui = (unsigned) -1, or if the value is not changed by the conversion like in abs (2.0). Warnings about conversions between signed and unsigned integers can be disabled by using -Wno-sign-conversion.

For C++, also warn for confusing overload resolution for user-defined conversions; and conversions that never use a type conversion operator: conversions to void, the same type, a base class or a reference to them. Warnings about conversions between signed and unsigned integers are disabled by default in C++ unless -Wsign-conversion is explicitly enabled.

-Wfloat-conversion
Warn for implicit conversions that reduce the precision of a real value. This includes conversions from real to integer, and from higher precision real to lower precision real values. This option is also enabled by -Wconversion.

-Wlogical-op
Warn about suspicious uses of logical operators in expressions. This includes using logical operators in contexts where a bit-wise operator is likely to be expected.

-Weffc++ (C++ and Objective-C++ only)
Warn about violations of the following style guidelines from Scott Meyers' Effective C++ series of books:

Define a copy constructor and an assignment operator for classes with dynamically-allocated memory.
Prefer initialization to assignment in constructors.
Have operator= return a reference to *this.
Don't try to return a reference when you must return an object.
Distinguish between prefix and postfix forms of increment and decrement operators.
Never overload &&, ||, or ,.

This option also enables -Wnon-virtual-dtor, which is also one of the effective C++ recommendations. However, the check is extended to warn about the lack of virtual destructor in accessible non-polymorphic bases classes too.

When selecting this option, be aware that the standard library headers do not obey all of these guidelines; use ‘grep -v’ to filter out those warnings.
i will begin one by one and check things out
Hi,

You could just use -Wall -Wextra -pedantic-errors to start with, see what that produces :+) Otherwise, there is no harm in enabling all the warnings I mentioned. With -Weffc++ , you might get warnings about code in a system header file, as long as it doesn't report warnings about your code - you could turn that one off for the release build.

With the style of your code:

You have a lot of variable names with one or several lower case letters at the start. Do these have some meaning in the literature? It's just that it looks like some form of Hungarian Notation, which is renowned for creating confusion or lack of understanding. One could have a more meaningful name, or at least provide a comment with the declaration as to what it means. Note that this query is not related to your spoken language being different to mine :+)

I think you could do with more functions: There is a kind of a guideline that functions should be no longer than 40LOC, including main , some go for even less. This aids understanding also.

Have you considered splitting your classes into header (.hpp) and implementation (.cpp) files? This is much more flexible for larger programs: one can include the header which is needed.

Good Luck !!
this is a project for thermal systems and equipment, so i am required to use those as such.

let's say DaN: D is for flow-> Da is airflow -> DaN means airflow in normal state

tAprim = air temperature that enters the equipment in totations it is tA' but i cannot use that notation so took the equivalent prime/prim

DgN gas flow in normal state
tGprim gas temperature

those notations i found easier to understand and are in romanian, i do not know any standard since i never wrote code until now
and if i wrote them in English some people may not understand them

i did a project for a class(handwritten and using a scientific calculator) and since it getting gradually more complicated i thought i should write it in code to learn

Last edited on
those notations i found easier to understand and are in romanian, i do not know any standard since i never wrote code until now
and if i wrote them in English some people may not understand them


No worries, you are of course entitled to program in your own language :+) And if they match up to the documentation that's perfectly fine.

i did a project for a class(handwritten and using a scientific calculator) and since it getting gradually more complicated i thought i should write it in code to learn


That's awesome, a good way to learn stuff :+)

It's not a bad idea to put a comment for a link to some documentation (wiki say)

How are you going using the debugger? Hopefully there is a GUI one in your IDE, if not there are command line versions. You should be able to step through the code 1 line at a time, with a watch list of variables that shows their values as you go along, thus deducing where things go wrong. That's the easiest way to sort out problems if the code compiles without warnings.

It's late at my end, I might not be up for much longer. There are plenty of others way more knowledgeable than me who can help :+)
after adding -Wconversion i got a warning
it is related to abs

PEITmain.cxx:502:34: warning: conversion to ‘int’ from ‘double’ may alter its value [-Wfloat-conversion]
epsilonTGsec = (abs(epsilonabs) / iGsecundStelat[interTG - 1]);

i will check things out, and review the code

thanks!

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
		 //initialise i with 0 so that it starts with the already known variable since we cant to find temp[i=1] knowing ig[i=0] and cgm[i=0] from formula tg=ig/cgm
		double epsilonTGsec{100}; int interTG{0};
		while (epsilonTGsec >= 0.01){
			double tGInt = iGsecundStelat[interTG] / cGmsecundStelat[interTG];
			tGsecundStelat.emplace_back(tGInt);
			double cGmInt = InterpolareCalduraSpecificaGaze(tGsecundStelat[interTG], compozitiaG);
		    cGmsecundStelat.emplace_back(cGmInt);			
			double iGsec = cGmsecundStelat[interTG] * tGsecundStelat[interTG-1];
			iGsecundStelat.emplace_back(iGsec);
			double epsilonabs=iGsecundStelat[interTG] - iGsecundStelat[interTG - 1];
			epsilonTGsec = (abs(epsilonabs) / iGsecundStelat[interTG - 1]);
			if (epsilonTGsec < 0.01){
				double tGsec= tGsecundStelat[interTG];
				std::cout << "tGsecund = " << tGsec << " grade C\n";
			}
			else interTG++;
		}


In this code, interTG is zero the first time in the loop, so tGsecundStelat[interTG-1] is trying to access out of bounds, subscript [-1]. Is that causing a problem ?

Not sure why you have a -Wconversion warning there, they all seem to be doubles? Although if the compiler says it's a warning, then it is - somehow :+) Are you calling the std::abs which has overloads for different types, and not the C abs which is for ints? Edit: See next post Can't tell, you don't have the includes for main, you need #include <cmath>

Edit: your includes at the start should use the <> format rather than the "" format for the system includes.

Line 70: if that is true, the while continues to loop, but interTG is not incremented, do you need a break; after line 72?
Last edited on
Are you calling the std::abs which has overloads for different types, and not the C abs which is for ints?


Sorry I had that backwards :+(

Looks like you are calling the C abs (for int), you need the std::abs which is in #include <cmath>
shouldn't the loops stop at that point, since epsilonTGsec should at that point be < 0.01 (that is why i did not use break)


so i added <cmath> and the warning is gone, i modified the while loop to be so:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
double epsilonTGsec{100}; int interTG{0};
		while (epsilonTGsec >= 0.01){
			double tGInt = iGsecundStelat[interTG] / cGmsecundStelat[interTG];
			tGsecundStelat.emplace_back(tGInt);
			double cGmInt = InterpolareCalduraSpecificaGaze(tGsecundStelat[interTG], compozitiaG);
		    cGmsecundStelat.emplace_back(cGmInt);			
			double iGsec = cGmsecundStelat[interTG+1] * tGsecundStelat[interTG];
			iGsecundStelat.emplace_back(iGsec);
			double epsilonabs=iGsecundStelat[interTG+1] - iGsecundStelat[interTG];
			epsilonTGsec = (std::abs(epsilonabs) / iGsecundStelat[interTG]);
			if (epsilonTGsec < 0.01){
				double tGsec= tGsecundStelat[interTG];
				std::cout << "tGsecund = " << tGsec << " grade C\n";
				break;
			}
			else interTG++;
		}


however i still get inf as a result
i will check behind to see if somehow something is divided by zero, maybe that's where the problem is...
i will check behind to see if somehow something is divided by zero, maybe that's where the problem is...


Are you using the debugger to do that?

Also, a defensive coding mechanism is to actually check the denominator is not very near to zero before you do any division. That is, less than some number you consider to be near enough to zero, like 0.001 or whatever value suits the mathematics / realities of what you are doing.

Edit:
With emplace_back , that is normally used to construct and object in a container, could just use push_back if it's only a double.
Last edited on
so i fixed it, with push_back instead of emplace_back, and there was something divided by 00 instead of 100 that didn't enter any equation until this loop
Topic archived. No new replies allowed.