Why my programs doesn't work? it just doesn't make math. Program doesnt print a at all. and prints that "A SUM = 0". I have to make a program that counts a, m goes in interval from 2 to -2 by -0.5, and n goes from 1 to 5 by 1. formula is a = (m*m) / (n-m). I have to use for....
I mean console appears like:
MY PROGRAM
Enter N and M
N: 1
M: 2
A RESULTS
A SUM = 0.000
line 22 checks if n>=m>o if true does the a = .... its in my work description it has to be included. programs has to check it.
btw the one you said helped ! but now it doesn't stop O_O counts to infinity... it shout count only while mprad is <= mgal... so 8 times i think... cuz 2+(-0.5) every time...
cout << "Salyga netenkinama";
cout << fixed << setprecision(2) << a << endl;
sum = sum + a;
be part of your 'else' condition or just the first line? You calculate the value for 'a' when the if evaluates to true, but if it doesn't you're going to print garbage out to the screeen because you are not initialising 'a'.
At line 20, the condition you have is mprad >= mgal. Since neither of these variables gets modified inside the loop, the condition never becomes false. I think the condition you want is m <= mgal.
Regarding the if/else, you are correct, if the condition in the if statement is false then the program executes the else part (if there is an else part).
be part of your 'else' condition or just the first line? You calculate the value for 'a' when the if evaluates to true, but if it doesn't you're going to print garbage out to the screeen because you are not initialising 'a'.
no just the first line, is there something wrong as well? and i don't get if what are you saying about "initialising 'a'"could u show the code for me?
and is the if right now?
1 2 3 4 5 6 7 8 9 10 11 12
for (m=mprad; m >= mgal; m=m+h1){
for (n = nprad; n <= ngal; n = n + h2){
if ( (n>=m) && (m>0) ){
a = (m*m) / (n-m);}
else
{cout << "Salyga netenkinama";}
cout << fixed << setprecision(2) << a << endl;
sum = sum + a;
}
}
dhayden, yes but it was still m >= mgal thanks very much
i found this out as well, but don't know how to set it, could u help me guys?
1 2 3 4 5 6 7 8 9 10
for (m=mprad; m >= mgal; m=m+h1){
for (n = nprad; n <= ngal; n = n + h2){
if ( (n>=m) && (m>0) ){
a = (m*m) / (n-m);
sum = sum + a;
cout << fixed << setprecision(2) << m << " " << n << " " << a << endl;
}
else
{cout << "Salyga netenkinama"<< "\n";}
in this code i have to set , that a = (m*m) / (n-m); (n-m) can't be equal to 0