### Else without a previous if

closed account (jhXS8vqX)
Hello. I meet a problem in my code(fragment of a code):
 ``12345678910`` `````` if(calitate == 0.065 && esantion_dublu < 500) A1 = 0; R1 = 1; A2 = 0; R2 = 1; else if(calitate == 0.065 && esantion_dublu == 500) A1 = 0; R1 = 2; A2 = 1; R2 = 2;``````

Error: else without a previous if.. how can I do? Thank you.
Last edited on
Use brackets { } for multi-statement bodies of if statements.

 ``123456789101112`` ``````if (a) { b; c; d; } else if (e) { f; g; h; }``````

http://www.cplusplus.com/doc/tutorial/control/
Last edited on
closed account (jhXS8vqX)
In final of code i want to see:

cout<<"Numarul de componente pentru care accept lotul [A1]: "<<A1<<endl;
cout<<"Numarul de componente pentru care resping lotul [R1]: "<<R1<<endl;
cout<<"Numarul de componente pentru care accept lotul [A2]: "<<A2<<endl;
cout<<"Numarul de componente pentru care resping lotul [R2]: "<<R2<<endl;

I make what did you said, but terminal print A1=0, R1=0, A2=93743638, R2=0..
Hey,
you appear to be comparing a double using equality. this often fails. It may not be entering either statement because calitate == 0.065 may never be true.
consider
if( abs(calitate - 0.065) > 0.001 && … //0.001 is an example it can be smaller