Help Please New to C++

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Feb 2008
Posts: 69
Reputation: Moporho is an unknown quantity at this point 
Solved Threads: 0
Moporho Moporho is offline Offline
Junior Poster in Training

Help Please New to C++

 
0
  #1
Feb 22nd, 2008
Hello,

I am trying to create a program that asks a user to input a integer. That integer will dispaly "*" (i.e. enter 4 diplay - ****)

This is what I came up with so far to no luck!

  1. #include "stdafx.h"
  2. #include <iostream>
  3. using std::cout;
  4. using std::cin;
  5. using std::endl;
  6.  
  7.  
  8. int main()
  9. {
  10. int n;
  11.  
  12. cout << "Please enter a integer ";
  13. cin >> n;
  14.  
  15. for (int i = n; i <= 25; n++)
  16. {
  17. cout << "*" ;
  18. }
  19.  
  20. cout << endl;
  21.  
  22. return 0;
  23. }
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 111
Reputation: jesseb07 is on a distinguished road 
Solved Threads: 15
jesseb07's Avatar
jesseb07 jesseb07 is offline Offline
Junior Poster

Re: Help Please New to C++

 
0
  #2
Feb 22nd, 2008
Hey, looking at your program looks like you have a few simple errors, logic and otherwise.

#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;


int main()
{
int n;

cout << "Please enter a integer ";
cin >> n;

for (int i = n; i <= 25; n++)
{
cout << "*" ;
}

cout << endl;

return 0;
}


#include "stdafx.h"

should be

#include <stdafx.h>

except when I ran it through my compiler it had no idea what that was, so when I removed it, it didn't affect functionality, so I'm not familiar with that one.

in your for loop, try this:

for (int i = 1; i <= n; i++)
{
cout << "*" ;
}

the reason for this is that the way you had it set up is that it would always display 25-n "*"'s which as I gather is not what you want. you also had n incrementing instead of the looping variable which it should have been. Chances are your program just kept on spitting out "*"'s indefinitely since the for loop would never be satisfied.

With that code modified it compiled and ran fine for me, let me know if it works for you.

Hope it helps!

~J
Last edited by jesseb07; Feb 22nd, 2008 at 11:37 pm.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 69
Reputation: Moporho is an unknown quantity at this point 
Solved Threads: 0
Moporho Moporho is offline Offline
Junior Poster in Training

Re: Help Please New to C++

 
0
  #3
Feb 23rd, 2008
Thank you so much!

My compiler generates that # include file. I used my other computer and it worked perfectly.

Thank you!
MPR
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum


Views: 394 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC