Delete kth node from last in LL

#include
using namespace std;

class node{
public:
int data;
node* next;
node(int d){
data = d;
next =NULL;
}
};

void insertAtTail(node* &head,int data){
node* tmp = head;
while(tmp->next!=NULL){
tmp = tmp->next;
}
node* new_node = new node(data);
tmp->next = new_node;
}

void kthNode_last(node* &head,int k){
if(head==NULL){cout<<“empty list”<<endl;}
node* slow=head;
node* fast= head;
node* prv=NULL;
for(int i =1;i<k;i++){
fast = fast->next;
}
while(fast->next!=NULL){
fast = fast->next;
prv=slow;
slow = slow->next;
}
cout<data<<endl;
// delete the data
prv=prv->next->next;
delete slow;
}
int main() {
node* head=NULL;
int n,m,k;
cin>>n;
while(n–){
cin>>m;
insertAtTail(head,m);
}
cin>>k;
kthNode_last(head,k);
}

THROWS RUNTIME ERROR.