Oct 21, 2010 at 8:00am UTC
hi guys please i need your help. i wrote and compiled a program to input name and number. the program actually was made but am unable to input anything in the answer sheet.this is the program;
// directory
# include <iostream>
# include <string>
# include <fstream>
# define getline
using namespace std;
struct directory {
string name;
int number;
}mine, yours;
void printdirectory (directory data){
string mystr;
cout <<yours.name <<yours.number;
}
int main (){
string mystr;
mine.name= "simonpeter";
mine.number = 806-778-8636;
cout<<"enter name: " << yours.name<< endl;
cout<<"emter number: " <<yours.number<<endl;
cout<<"you have entered:\n";
printdirectory (yours);
return 0;
}
Oct 21, 2010 at 8:09am UTC
Use cin for input:
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 35 36
# include <iostream>
# include <string>
# include <fstream>
using namespace std;
struct directory {
string name;
int number;
}mine, yours;
void printdirectory (directory data){
string mystr;
cout <<yours.name <<yours.number;
}
int main (){
string mystr;
mine.name= "simonpeter" ;
mine.number = 806-778-8636;
cout<<"enter name: " ;
cin >> yours.name;
cout <<endl;
cout<<"emter number: " ;
cin >>yours.number;
cout<<endl;
cout<<"you have entered:\n" ;
printdirectory (yours);
return 0;
}
EDIT:
mine.number = 806-778-8636;
Do you want to input a phone number? If so, then you must use string for that too.
Last edited on Oct 21, 2010 at 8:13am UTC
Oct 21, 2010 at 8:11am UTC
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 35
// directory
#include <iostream>
#include <string>
#include <fstream>
#define getline
using namespace std;
struct directory
{
string name;
int number;
} mine, yours;
void printdirectory (directory data)
{
string mystr;
cout << yours.name << "\n" << yours.number;
}
int main ()
{
string mystr;
mine.name= "simonpeter" ;
mine.number = 806-778-8636;
cout<< "enter name: " ;
cin >> yours.name;
cout<< "enter number: " ;
cin >> yours.number;
cout<<"you have entered:\n" ;
printdirectory (yours);
return 0;
}
[edit]
Man, too slow :(
Last edited on Oct 21, 2010 at 8:13am UTC