Help in correcting my code

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Jun 2008
Posts: 117
Reputation: kavithabhaskar is an unknown quantity at this point 
Solved Threads: 0
kavithabhaskar kavithabhaskar is offline Offline
Junior Poster

Help in correcting my code

 
0
  #1
Nov 9th, 2008
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



  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 >
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,358
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1464
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Help in correcting my code

 
0
  #2
Nov 9th, 2008
>>for(i=i;i<10;++i)

should be for(i = 0 ...
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 118
Reputation: chococrack is on a distinguished road 
Solved Threads: 14
chococrack's Avatar
chococrack chococrack is offline Offline
Junior Poster

Re: Help in correcting my code

 
0
  #3
Nov 19th, 2008
I get lots of pretty output, (gcc compiler):

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-...

  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

  1. #include <iostream>

...

  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 ~
  1.  
  2. for(int i=0; i<10; i++)
  3. cout << "." << i;

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




  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.

  1.  
  2.  
  3. return 0;
  4. }
I would love to change the world, but they won't give me the source code
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC