Post your doubts in C++ - Page 2

Created

Last reply

Replies

12

Views

1.5k

Users

4

Frequent Posters

akhl thumbnail
18th Anniversary Thumbnail Dazzler Thumbnail Fascinator 1 Thumbnail
Posted: 17 years ago
#11
Vanshika,
One more thing. In your program, I find used in a few places. This is HTML code for white space. Is this there in your program or does it only appear in your post in this thread because of some technical problem?
akhl thumbnail
18th Anniversary Thumbnail Dazzler Thumbnail Fascinator 1 Thumbnail
Posted: 17 years ago
#12
See the beginning of main.
You have written: -

for(int s=1000;s>100;s+50)
{
sound(s);
delay(50);
}
s+50 has no effect. May be you want to increment the value of s by 50. If so, then you should write s+=50. But that results into another problem, as described below.
The condition is that s should be greater than 100. Initial value of s is 1000, which is greater than 100. This means that initial value satisfies the condition. So far good. But after every loop, you are increasing the value of s by 50. If initial value is >100, then every value will also be >100, because you are increasing the value of s. Don't you think it will result in infinite for loop?
Only thing that can save is that s will become so large that it will not fit within int. Then s will become negative and loop will break. But this is bad programming. Moreover, it is still very time consuming loop. The system will become extremely slow.
So, let me know why you have put that for loop. Then, I will think of alternative.
Edited by akhl - 17 years ago
akhl thumbnail
18th Anniversary Thumbnail Dazzler Thumbnail Fascinator 1 Thumbnail
Posted: 17 years ago
#13
Vanshika,
Do you still need help with that program? If yes, then please answer what I asked. Then I will understand your problem in detail and will be in a better position to help.

Related Topics

Top

Stay Connected with IndiaForums!

Be the first to know about the latest news, updates, and exclusive content.

Add to Home Screen!

Install this web app on your iPhone for the best experience. It's easy, just tap and then "Add to Home Screen".