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.
usingnamespace 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");
}
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.