Hey, i am making a program that is basscially a database for information of my friends, it is simple and just to test my knowledge. However, I was wondering if there is a way to let the user input where the ptr-> is going to point to? For example
at the ptr = &(this is where i want the string to be put). Whenever I try and do this it doesnt work, is there any way?Code:#include <iostream> using namespace std; struct friends { int grade; int age; int phone; }; int main(){ int input; int frinput; int again; string name; friends *ptr; friends sam; sam.grade = 9; sam.age = 15; sam.phone = 9857685; friends carlos; carlos.grade = 9; carlos.age = 15; carlos.phone = 9756642; friends alex; alex.grade = 9; alex.age = 15; alex.phone = 9928346 ; top: cout<<"Welcome to sam's friends database:\n"; cout<<" Enter the name of the person who's info you want to see, or ""list"" to see who is in the dtabase: "; cin>>name; if (name=="list"){ cout<<"In the friend's database you can access:\n sam \n alex \n carlos \n\nPress Enter to Continue"; cin.get(); cin.ignore(); goto top; } else{ ptr = & ;//this is the part I have trouble with cout<<"\n\nYou have accesed "<<name<<"'s info:"; cout<<"\n Grade: "<< ptr->grade<<"\n Age: "<<ptr->age<<"\n Phone: "<<ptr->phone; cout<<"\n\n Back to main menu? \n 1. Yes\n 2. No\n"; cin>>again; if (again == 1){ goto top;} else{ return 0;} } }



LinkBack URL
About LinkBacks


