This is a discussion on Problems with an If loop.. within the C++ Programming forums, part of the General Programming Boards category; Originally Posted by oogabooga (And don't mix tabs and spaces ... get rid of all tabs.) Who are you to ...
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
I'm more concerned with repetition of the code and it outputting whether or not it's right. I am able to make it repeat, but it won't output the outcome anymore.I must be missing something within these statements?Code:{ for (int j = 0; j < 10; ++j) random_integer1 = lowest+int(range*rand()/(RAND_MAX + 1.0)); random_integer2 = lowest+int(range*rand()/(RAND_MAX + 1.0)); cout << "If I add " << random_integer1 << " and " << random_integer2 << " then what do I have? " << endl; cin >> answer; realanswer=random_integer1+random_integer2; }
Are you even listening or reading replies?
Fix the tabs/spaces problem. Fix the brace problem and then THINK. Read the code back here.
Why are we wasting time on you when you aren't listening? If you don't understand, then mention so!
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
I'm pretty ignorant.
What part do you not understand?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Well You guys are telling me to get rid of all my spaces/tabs, and I really don't understand how thats going to solve my problem. It's probably more of a style thing so that it's easier for you to look at. I don't know, i'm just messy. I really haven't taken any classes to speak of so I'm at a disadvantage. Still If you tell me how you think I should structure my program based on tabs/spaces I will do so. I just need a layman's explanation. I'm not pro.
Yes, but we need to able to read your code, no?
That's why we keep telling you to use only one of them. Either tabs or just spaces. It's called indentation and it's very important to make others be able to read your code as well to help you catch mistakes.
Unfortunately, I can't tell you which one to use. You'll have to make up your own mind on that. Here is a good vs list:
http://cpwiki.sourceforge.net/User:E..._Disadvantages
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
Seems a little irrelevant to me but then again i'm used to looking at my own code and I see differently than you might.
Code:#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand((unsigned)time(0)); int answer,i; int realanswer; int random_integer1; int random_integer2; int lowest=0, highest=49; int range=(highest-lowest)+1; char ch; for (int j = 0; j < 10; ++j) { random_integer1 = lowest+int(range*rand()/(RAND_MAX + 1.0)); random_integer2 = lowest+int(range*rand()/(RAND_MAX + 1.0)); cout << "If I add " << random_integer1 << " and " << random_integer2 << " then what do I have? " << endl; cin >> answer; realanswer=random_integer1+random_integer2; } for (int j = 0; j < 10; ++j) { for(i=0;i<2;i++) { if (answer == realanswer) { cout<<"You are Right"<<"\n"; break; } else { if(i==1) { cout<<"You are wrong. The right answer is "<<realanswer<<"\n"; } else { cout<<"Oops! You are wrong. Try again...\n"; cin>>answer; } } } } }
Huh? Now you destroyed it even more and fixed nothing.
Read, read, read, read, read please.
http://cpwiki.sf.net/User:Elyisa/Indentation
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
does that mean I only hit it once, because everything just lines up and the eye won't see the difference in the statements...?
Okay so now I did spaces. Whatya think?
Code:#include <iostream> #include <ctime> #include <cstdlib> using namespace std; int main() { srand((unsigned)time(0)); int answer,i; int realanswer; int random_integer1; int random_integer2; int lowest=0, highest=49; int range=(highest-lowest)+1; char ch; for (int j = 0; j < 10; ++j) { random_integer1 = lowest+int(range*rand()/(RAND_MAX + 1.0)); random_integer2 = lowest+int(range*rand()/(RAND_MAX + 1.0)); cout << "If I add " << random_integer1 << " and " << random_integer2 << " then what do I have? " << endl; cin >> answer; realanswer=random_integer1+random_integer2; } for (int j = 0; j < 10; ++j) { for(i=0;i<2;i++) { if (answer == realanswer) { cout<<"You are Right"<<"\n"; break; } else { if(i==1) { cout<<"You are wrong. The right answer is "<<realanswer<<"\n"; } else { cout<<"Oops! You are wrong. Try again...\n"; cin>>answer; } } } } }
Yes, you're using only spaces, but the indentation is severely messed up (which is clearly your mistake and not due to unforeseen problems beyond your control such as mixing of spaces/tabs), which is why I wanted you to read the article. Is there something you did not understand or wasn't perfectly clear?
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^
You want me to indent with 4 or 8?
I thought his code was mostly spaces with a few tabs messing it up. Now that I look back it seems the other way round (duh). I just meant to change them to the same thing. It's the _mixing_ I can't stand!Who are you to judge?
To Sedvan: to say people's advice is "irrelavant" is pathetic. Programming is about communication, with the machine _and_ with people. Coding style is common courtesy, as well as a no-brainer for people with any experience. If you want people's advice (read "time"), then you have to meet them halfway. Personally, I can't believe how gracious the explicators here are sometimes. But for their example I would say "scrap it and take up knitting".
(Note: He's posting this on multiple sites and seemlingly just accumulating code as he goes.)
Then you should have mentioned so! It seemed to me like you were just a "tab hater" and wanted to the OP to use all spaces instead.
I agree with you that the mixing is bad and messed up a lot.
4 is fine. But the real problem is the indentation levels and bracket placement which is way wrong. Re-read the link I posted.
Last edited by Elysia; 01-29-2008 at 09:41 AM.
For information on how to enable C++11 on your compiler, look here.
よく聞くがいい!私は天才だからね! ^_^