i/o problem

hi.
i'm a newbie in c++ but have some minor background in c.
using VS2010 on win7, i am trying to write a func that receives a name and int and prints duplicates of the name according to the integer. if no integer is given it will print 10 times.

i wrote it and a main func to test it. it builds, but when i run it with F5, after typing in a name, i get the:"how many times to type it?" output line and the prgram ends. so i can't enter the integer.

any suggestions to what's happening?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
using namespace std;
#include<iostream>


void PMPrint(char *name="yoad", int n=10)
{
	int i=0;
	while (i<n)
	{
		cout<<name<<endl;
		i++;
	}
}


void main()
{
	char User, *p_user;
	int m=0;

	cout<<"what is your name?"<<endl;
	cin>>User;

	cout<<"how many times to type it?"<<endl;
	cin>>m;
	
	p_user=&User;
	
	PMPrint(p_user, m);

	system("PAUSE");

}


Last edited on
User is a char, not a char[], so it can only store one character. You need an array to read directly into, or you could do it the C++ way and use a std::string.
fixed it, solved my problem....i'm a bit rusty in coding. thanks!
Topic archived. No new replies allowed.