Advertisement
Guest User

Untitled

a guest
Mar 25th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. struct test{
  5. char name[30];
  6. int age;
  7. };
  8.  
  9. void addStudent(struct test *ptrTest,int *totalStudent){
  10. for(int i=0;i<2;i++){
  11. cout<<"nInsert the name: ";
  12. cin.sync();
  13. cin.getline(ptrTest->name,sizeof(ptrTest->name));
  14. cout<<"nInsert the age: ";
  15. cin.sync();
  16. cin>>ptrTest->age;
  17. *totalStudent+=1;
  18. }
  19.  
  20. }
  21.  
  22. void showStudent(struct test *ptrTest,int totalStudent){
  23. for(int i=0;i<totalStudent;i++){
  24. cout<<"nName: "<<ptrTest->name;
  25. cout<<"nAge: "<<ptrTest->age;
  26. }
  27. };
  28.  
  29. int main()
  30. {
  31. struct test t;
  32. addStudent(&t,&totalStudent);
  33. showStudent(&t,totalStudent);
  34. return 0;
  35. }
  36.  
  37. int main()
  38. {
  39. struct test t;
  40. // LIKE THIS
  41. int totalStudent;
  42.  
  43. addStudent(&t,&totalStudent);
  44. showStudent(&t,totalStudent);
  45. return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement