943,865 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 384
  • C++ RSS
Nov 9th, 2008
0

Help in correcting my code

Expand Post »
Hi:

I need some assistance in this code. I am trying to get this format.

1
.2
..3
...4
and so on.. i dont get any errors in the code but i get no o/p eitehr



C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>
  2.  
  3. int main()
  4. {
  5.  
  6. int i;
  7.  
  8. cout.fill('.');
  9.  
  10. for(i=i;i<10;++i)
  11.  
  12. {
  13. cout.width(i);
  14. cout.fill('.');
  15. cout<<i;
  16.  
  17.  
  18. }}
Last edited by Ancient Dragon; Nov 9th, 2008 at 12:56 pm. Reason: correct code tags -- use [ and ], not < and >
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster
kavithabhaskar is offline Offline
123 posts
since Jun 2008
Nov 9th, 2008
0

Re: Help in correcting my code

>>for(i=i;i<10;++i)

should be for(i = 0 ...
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,951 posts
since Aug 2005
Nov 19th, 2008
0

Re: Help in correcting my code

I get lots of pretty output, (gcc compiler):

Quote originally posted by output ...
..-1208080203-1208080202-1208080201-1208080200-1208080199-1208080198-1208080197-
1208080196-1208080195-1208080194-1208080193-1208080192-1208080191-1208080190-
1208080189-1208080188-1208080187-1208080186-1208080185-1208080184-1208080183-
1208080182-1208080181-1208080180-1208080179-1208080178-1208080177-1208080176-
1208080175-1208080174-1208080173-1208080172-1208080171-1208080170-1208080169-
1208080168-1208080167-1208080166-1208080165-1208080164-1208080163-1208080162-
1208080161-1208080160-1208080159-1208080158-1208080157-1208080156-1208080155-
1208080154-1208080153-1208080152-1208080151-1208080150-1208080149-1208080148-
1208080147-1208080146-1208080145-1208080144-1208080143-1208080142-1208080141-
1208080140-1208080139-1208080138-1208080137-1208080136-1208080135-1208080134-
1208080133-1208080132-1208080131-1208080130-1208080129-1208080128-1208080127-...

C++ Syntax (Toggle Plain Text)
  1. #include<iostream.h>

While it does not really matter if your compiler supports this, its usually a better idea to use the most recent header files

C++ Syntax (Toggle Plain Text)
  1. #include <iostream>

...

C++ Syntax (Toggle Plain Text)
  1. cout.fill('.');
  2. for(i=i;i<10;++i)
  3. {
  4. cout.width(i);
  5. cout.fill('.');
  6. cout<<i;
  7. }

INT X: You declare a variable and do not initialize it.

FOR X = X: You copy the value of X into X,

FOR (X to 10): Well based on the value we gave X (none) this could be anywhere in the range of integer values ( -2147483648 to 2147483647, on a 32-bit system ) number of iterations.

[code]
int x = 0;
for(i = x; i<10; ++i)
cout << "." << i;
[code]

~ or ~
C++ Syntax (Toggle Plain Text)
  1.  
  2. for(int i=0; i<10; i++)
  3. cout << "." << i;

Would accomplish what you're looking for in your loop.




C++ Syntax (Toggle Plain Text)
  1.  
  2.  
  3.  
  4. }

There is no return 0; The system needs this value to know everything went 'ok' with the system.. any other value that is returned is usually viewed as an error.

C++ Syntax (Toggle Plain Text)
  1.  
  2.  
  3. return 0;
  4. }
Reputation Points: 92
Solved Threads: 16
Junior Poster
chococrack is offline Offline
149 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Confusions related to Dll.
Next Thread in C++ Forum Timeline: Inheritance Trouble





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC