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!

#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;
}

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

Thank you so much!

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

Thank you!
MPR

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.