Posted October 28, 2014 #include <iostream> #include <cmath> using namespace std; void main() { float m,n,xpm,xgm,xpn,xgn,hx1,hx2,a,sum; cout << "Type in xpm ir xgm: " << endl; cin >> xpm >> xgm; cout << "Type in xpn ir xgn" << endl; cin >> xpn >> xgn; cout << "Type in hx1 ir hx2: " << endl; cin >> hx1 >> hx2; m = xpm; n = xpn; sum = 0; a = 0; while (n>=m>0) { for (m = xpm; m >= xgm; m = m + hx1) { for (n = xpn; n >= xgn; n = n + hx2) { a = (m*m) / (n - m); sum = sum + a; } } } cout << "A: " << a << endl; cout << "Suma: " << sum << endl; } Doing this for college and this just makes my head hurt because i get this. When i run it when i type in the numbers it gives an answer 0. Why can anyone solve plz Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/ Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 @z3kron Well, for the starters, use actual names for your variables....names that describe what they do, thats just brutal to read. Also, your while loop won't work. Do: while(n>=m && m >0)P.s. whats the code supposed to do? PSU Tier List | CoC Gaming Build | FreeNAS Server Spoiler i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core Spoiler FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210. Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297226 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Also, please use code tags. edit: Thanks for the edit. Proper spacing is helpful too Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297240 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Author @z3kron Well, for the starters, use actual names for your variables....names that describe what they do, thats just brutal to read. Also, your while loop won't work. Do: while(n>=m && m >0)P.s. whats the code supposed to do? Well im really new to this and im doing this just to work.All the polishing will come in later. So while(n>=m && m >0) how should this look like? && means? Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297267 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Well im really new to this and im doing this just to work.All the polishing will come in later. So while(n>=m && m >0) how should this look like? && means? && is logical and || is logical or. && means that both conditions must be met while || means that only one of the conditions must be met. But what is the code supposed to do? PSU Tier List | CoC Gaming Build | FreeNAS Server Spoiler i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core Spoiler FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210. Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297282 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Id also welcome some indentations, mostly inside the while loop. The spacing between each "}" confuses me too As you are new in this, let me tell you this: it's important to use legible and clear sintax and well explained variables, even more if you are planning to show this to anyone (us if you are searching for help). You know whats going on in the program, what are its functions, etc, for the rest of human beings, its just too braindraining having to decipher all the functionality in the code, and you can simply take 5 seconds typing 'sum needs to be m+n if "propper variable name" is less than X.' or something like so. I can also see that there is no new velues for M or N being set inside the loop. It will go on forever as the conditions for it to be TRUE will always be TRUE. Planning on trying StarCitizen (Highly recommended)? STAR-NR5P-CJFR is my referal link Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297347 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Author && is logical and || is logical or. && means that both conditions must be met while || means that only one of the conditions must be met. But what is the code supposed to do? Its basicaly a calculating program with calculates m witch meanings change in the interval from 2 to -2 in a step of h1=-0.5 and n changes in an interval of 1 to 5 in a step h2=1 Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297349 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 I can also see that there is no new velues for M or N being set inside the loop. It will go on forever as the conditions for it to be TRUE will always be TRUE.m and n are set at the end of the for loops. PSU Tier List | CoC Gaming Build | FreeNAS Server Spoiler i5-4690k || Seidon 240m || GTX780 ACX || MSI Z97s SLI Plus || 8GB 2400mhz || 250GB 840 Evo || 1TB WD Blue || H440 (Black/Blue) || Windows 10 Pro || Dell P2414H & BenQ XL2411Z || Ducky Shine Mini || Logitech G502 Proteus Core Spoiler FreeNAS 9.3 - Stable || Xeon E3 1230v2 || Supermicro X9SCM-F || 32GB Crucial ECC DDR3 || 3x4TB WD Red (JBOD) || SYBA SI-PEX40064 sata controller || Corsair CX500m || NZXT Source 210. Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297361 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Author Id also welcome some indentations, mostly inside the while loop. The spacing between each "}" confuses me too As you are new in this, let me tell you this: it's important to use legible and clear sintax and well explained variables, even more if you are planning to show this to anyone (us if you are searching for help). You know whats going on in the program, what are its functions, etc, for the rest of human beings, its just too braindraining having to decipher all the functionality in the code, and you can simply take 5 seconds typing 'sum needs to be m+n if "propper variable name" is less than X.' or something like so. I can also see that there is no new velues for M or N being set inside the loop. It will go on forever as the conditions for it to be TRUE will always be TRUE. && is logical and || is logical or. && means that both conditions must be met while || means that only one of the conditions must be met. But what is the code supposed to do? Because im foreign and i learn every coding meaning in my native language its hard to understand what you want me to change. Can any of you just fix whats wrong in this code and send it here. Leave the spacings with those } but the main thing because its just too hard for me to understand. ( Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297363 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Its basicaly a calculating program with calculates m witch meanings change in the interval from 2 to -2 in a step of h1=-0.5 and n changes in an interval of 1 to 5 in a step h2=1 can you give an example of the outcome? I didnt quite get it with your explanation, sorry. PS- ye i can tell english is not your native languaje (same here, im spanish) just keep trying Planning on trying StarCitizen (Highly recommended)? STAR-NR5P-CJFR is my referal link Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297375 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Posted October 28, 2014 Author can you give an example of the outcome? I didnt quite get it with your explanation, sorry. PS- ye i can tell english is not your native languaje (same here, im spanish) just keep trying Ok this is my task for class. Make a code 'a' value calculator. Every 'm' , witch values 'm' change in the interval of 2 to -2 in a step of h1=-0,5 (basicaly whatever m is it changes in the range from 2 to -2 in a step of -0.5) and values of 'n' changing in the interval of 1 to 5 in a step of h2=2 ( same thing only the interval is 1 to 5 and step is 1). This what it should do. I'm just asking to fix my mistake witch i probably made in the code witch gives me an answer 0 no mater what number i type in in the meaning of m and n Link to comment https://linustechtips.com/topic/240510-c-whats-wrong/#findComment-3297443 Share on other sites More sharing options... Link to post Share on other sites More sharing options...
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now