0

Compile ignore input from user when add new data ...How it solve

#include<iostream> #include<fstream> using namespace std; struct variable { char name,sex[5], blood_grp, address, choice; int donor_no, age; }; void add_new_data() { variable v; char a; re_data_enter: cout << " ===========================================" << endl; cout << " | BLOOD BANK SYSTEM |" << endl; cout << " ===========================================" << endl; cout << endl; cout << "Enter the Donor no. : "; cin >> v.donor_no; cin.ignore(); cout << "Enter the Donor name : " << endl; cin.get(v.name); cin.ignore(); cout << "Enter the Donor age : " << endl; cin>>v.age; cin.ignore(); cout << "Enter the Donor Sex : " << endl; cin.get(v.sex,5); cin.ignore(); cout << "Enter the Donor Blood Group : " << endl; cin.get(v.blood_grp); cin.ignore(); cout << "Enter the Donor Adress : " << endl; cin.get(v.address); cout << endl; cout << endl; cin.ignore(); cout << "Should You Add New Donor Data....(Y/N)" << endl; cin.get(v.choice);

28th Dec 2019, 2:25 PM
Ali wahid
Ali wahid - avatar
10 odpowiedzi
+ 2
in: struct variable, you have char name, sex[5],blood_grp, address, choice ; that means when you want to add new data your input have to be one character for name and address. example when you are asked to enter name, you have to enter one character only like (a) or (b) without parentheses. try running your program but only enter one character in every input.
28th Dec 2019, 5:54 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
your program does not have a main() function, if it is supposed to be the whole thing.
28th Dec 2019, 3:14 PM
Bahhaⵣ
Bahhaⵣ - avatar
+ 1
could you put the whole code in sololearn playground and put a link to it.
28th Dec 2019, 3:20 PM
Bahhaⵣ
Bahhaⵣ - avatar
28th Dec 2019, 3:26 PM
Ali wahid
Ali wahid - avatar
0
It have main () but always ignore user input ....these code are half
28th Dec 2019, 3:18 PM
Ali wahid
Ali wahid - avatar
0
Ok
28th Dec 2019, 3:21 PM
Ali wahid
Ali wahid - avatar
0
sorry I was busy I couldn't answer you sooner. in the struct you defined many variables as char. and some of them have to store more than one char. like name, address. if you want it to work you have to enter one char for every variable except sex[]. i.e Enter The Donor name : a you can not write more than one char. because that's how you defined name. change those variables to string.
28th Dec 2019, 5:23 PM
Bahhaⵣ
Bahhaⵣ - avatar
0
I CAN NOT UNDERSTAND ....PLEASE DEFINED IN WRITING FORM LIKE CODE WHICH I CHANGING IN CODE
28th Dec 2019, 5:48 PM
Ali wahid
Ali wahid - avatar
0
Ok
28th Dec 2019, 6:04 PM
Ali wahid
Ali wahid - avatar
0
And also tell next step to solve these problem
28th Dec 2019, 6:05 PM
Ali wahid
Ali wahid - avatar