954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

newcommer to c++ need help with simple program

hello all . well its pretty simple but i need to get this for loop sorted before i can move on.

#include <iostream.h>

void square();
void circle();
void arrow();
void diamond();

using std::cout;
using std::endl;

void square()
{
  //first line
  for (int e = 1; e >= 9; e++)
  {
   cout << "*";
  }

}


int main()
{
  square();
  return 0;
}


<< moderator edit: added [code][/code] tags >>

so thats it .. and it wont print the stars . if i comment out the loop then it will display a star. so i dont know whats going on i cant see any error in the syntax or logic. so any help is appreciated thank you.

rks01
Newbie Poster
7 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

In the "for", you stated the following:
e=1; e>=9; e++
So, it means that e is first 1 and it will grow each cycle while e>=9 (simply isn't possible-e=1). To correct this, just make the for like this:

for (e=1;e<=9;e++) ...

The Senate
Newbie Poster
7 posts since Jul 2005
Reputation Points: 10
Solved Threads: 1
 

ah thank you .. got it the wrong way round thank you!

rks01
Newbie Poster
7 posts since Jul 2005
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You