How can get the the full name using the getline function to show in case C. what do I need to add to show it? #include "stdafx.h" #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; struct donor { string donor_name[50]; double donor_amount[50]; int department_donation[50]; }; string find_name; double *NHTS; double *PBL; double *PTK; double *SEA; int search_display; int contributor; int display; int choice; int main() { here: cout << "\n"; cout << " ************************************************************" << endl; cout << " ** ==Menu== **" << endl; cout << " ** **" << endl; cout << " ** **" << endl; cout << " ** **" << endl; cout << " ** 1. Add a contributor. **" << endl; cout << " ** 2. Search and update contributor. **" << endl; cout << " ** 3. Display all Donor information. **" << endl; cout << " ** 4. Department Total. **" << endl; cout << " ** 5. Delete Donation. **" << endl; cout << " ** 6. Exit. **" << endl; cout << " ** **" << endl; cout << " ** Choose one: **" << endl; cout << " ** **" << endl; cout << " ** **" << endl; cout << " ** **" << endl; cout << " ************************************************************" << endl; COORD c; c.X = 34; c.Y = 13; SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), c); cin >> choice; int NumberOfDonors; donor *ptr, d; ptr = &d; switch (choice) { case 1: COORD c; c.X = 20; c.Y = 20; SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), c); cout << "\n|----------------------------------|" << endl; cout << "|==== Record donor information ====|" << endl; cout << "|----------------------------------|\n" << endl; cout << "Please enter the number of donors you want to enter: "; (cin >> NumberOfDonors).get(); { for (int i = 0; i < NumberOfDonors; i++) { cout << "\nPlease enter the name of the donor: \n"; getline(cin >> ws, d.donor_name[i]); cout << "\nPlease enter amount donor contributed: \n"; cin >> ptr->donor_amount[i]; cout << "\n=Donation to organization= \n"; cout << "\n1.)NHTS 2)PBL 3)PTK 4)SEA\n"; cout << "Pick the deparment number for donation:"; (cin >> ptr->department_donation[i]).get(); cout << "\nDonor information: \n" << endl; cout << "\nDonor name: " << d.donor_name[i] << endl; cout << "Donation amount: " << "$"<donor_amount[i] << endl; cout << "Donated to " << ptr->department_donation[i] << " department" << endl; } system("pause"); system("CLS"); } goto here; case 2: { COORD F; F.X = 20; F.Y = 20; SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), F); cout << "\n|-------------------------------------|" << endl; cout << "|=== Search and update contributor ===|" << endl; cout << "|-------------------------------------|\n" << endl; tryagain: cout << "\nPlease type in the name: \n"; cin.sync(); cin.ignore(); getline(cin >> ws, find_name); for (int i = 0; ; i++) { if (find_name == (*ptr).donor_name[i]) { cout << "Enter New Amount: " << endl; cin >> (*ptr).donor_amount[i]; } else { char try_again; cout << "I am sorry, we couldn't find that information.\n"; place: cout << "\nWould you like to try again? (Y/N): "; cin >> try_again; if (try_again == 'Y' || try_again == 'y') { goto tryagain; } if (try_again == 'N' || try_again == 'n') { system("CLS"); goto here; } else if (try_again != 'N' && try_again != 'n' && try_again != 'Y' && try_again != 'y') cout << "Invalid input please enter (Y/N). " << endl; goto place; } } system("pause"); } system("CLS"); goto here; case 3: { COORD D; D.X = 20; D.Y = 20; SetConsoleCursorPosition( GetStdHandle(STD_OUTPUT_HANDLE), D); cout << "\n|-----------------------------|" << endl; cout << "|=== Display all donations ===|" << endl; cout << "|-----------------------------|\n" << endl; cout << "|----------------------------|" << endl; cout << "| Name | Amount | Department |" << endl; for (int i = 0; i
How can get the the full name using the getline function to show in case C. what do I need to add to show it?
#include "stdafx.h"
#include <iostream>
#include <limits>
#include <cstdlib>
#include <ctime>
#include <string>
#include <vector>
#include <cctype>
#include <iterator>
#include <algorithm>
#include <cmath>
#include<windows.h>
#include <conio.h>
using namespace std;
struct donor
{
string donor_name[50];
double donor_amount[50];
int department_donation[50];
};
string find_name;
double *NHTS;
double *PBL;
double *PTK;
double *SEA;
int search_display;
int contributor;
int display;
int choice;
int main()
{
here:
cout << "\n";
cout << " ************************************************************" << endl;
cout << " ** ==Menu== **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** 1. Add a contributor. **" << endl;
cout << " ** 2. Search and update contributor. **" << endl;
cout << " ** 3. Display all Donor information. **" << endl;
cout << " ** 4. Department Total. **" << endl;
cout << " ** 5. Delete Donation. **" << endl;
cout << " ** 6. Exit. **" << endl;
cout << " ** **" << endl;
cout << " ** Choose one: **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ** **" << endl;
cout << " ************************************************************" << endl;
COORD c;
c.X = 34;
c.Y = 13;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), c);
cin >> choice;
int NumberOfDonors;
donor *ptr, d;
ptr = &d;
switch (choice)
{
case 1:
COORD c;
c.X = 20;
c.Y = 20;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), c);
cout << "\n|----------------------------------|" << endl;
cout << "|==== Record donor information ====|" << endl;
cout << "|----------------------------------|\n" << endl;
cout << "Please enter the number of donors you want to enter: ";
(cin >> NumberOfDonors).get();
{
for (int i = 0; i < NumberOfDonors; i++)
{
cout << "\nPlease enter the name of the donor: \n";
getline(cin >> ws, d.donor_name[i]);
cout << "\nPlease enter amount donor contributed: \n";
cin >> ptr->donor_amount[i];
cout << "\n=Donation to organization= \n";
cout << "\n1.)NHTS 2)PBL 3)PTK 4)SEA\n";
cout << "Pick the deparment number for donation:";
(cin >> ptr->department_donation[i]).get();
cout << "\nDonor information: \n" << endl;
cout << "\nDonor name: " << d.donor_name[i] << endl;
cout << "Donation amount: " << "$"<<ptr->donor_amount[i] << endl;
cout << "Donated to " << ptr->department_donation[i] << " department" << endl;
}
system("pause");
system("CLS");
}
goto here;
case 2:
{
COORD F;
F.X = 20;
F.Y = 20;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), F);
cout << "\n|-------------------------------------|" << endl;
cout << "|=== Search and update contributor ===|" << endl;
cout << "|-------------------------------------|\n" << endl;
tryagain:
cout << "\nPlease type in the name: \n";
cin.sync();
cin.ignore();
getline(cin >> ws, find_name);
for (int i = 0; ; i++)
{
if (find_name == (*ptr).donor_name[i])
{
cout << "Enter New Amount: " << endl;
cin >> (*ptr).donor_amount[i];
}
else
{
char try_again;
cout << "I am sorry, we couldn't find that information.\n";
place:
cout << "\nWould you like to try again? (Y/N): ";
cin >> try_again;
if (try_again == 'Y' || try_again == 'y')
{
goto tryagain;
}
if (try_again == 'N' || try_again == 'n')
{
system("CLS");
goto here;
}
else if (try_again != 'N' && try_again != 'n' && try_again != 'Y' && try_again != 'y')
cout << "Invalid input please enter (Y/N). " << endl;
goto place;
}
}
system("pause");
}
system("CLS");
goto here;
case 3:
{
COORD D;
D.X = 20;
D.Y = 20;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), D);
cout << "\n|-----------------------------|" << endl;
cout << "|=== Display all donations ===|" << endl;
cout << "|-----------------------------|\n" << endl;
cout << "|----------------------------|" << endl;
cout << "| Name | Amount | Department |" << endl;
for (int i = 0; i<NumberOfDonors; i++)
{
cout << "|----------------------------|" << endl;
cout << "|" << " "<<d.donor_name[i] << " " << " |" <<"$"<< d.donor_amount[i] << " " "|" <<" "<< d.department_donation[i] << "| " << endl;
}
cout << "|----------------------------|" << endl;
system("pause");
system("CLS");
goto here;
}
case 4:
{
COORD G;
G.X = 20;
G.Y = 20;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), G);
cout << "|--------------------------------|";
cout << "| ==Total Contributions== |";
cout << "|--------------------------------|";
cout << "| NHTS | PBL | PTK | SEA |";
cout << "|" << NHTS << "|" << PBL << "|" << PTK << "|" << SEA << "|";
cout << "|--------------------------------|";
}
system("pause");
system("CLS");
goto here;
case 5:
{
COORD E;
E.X = 20;
E.Y = 20;
SetConsoleCursorPosition(
GetStdHandle(STD_OUTPUT_HANDLE), E);
cout << "\n|-------------------------------|" << endl;
cout << "|=== Delete a donor donation ===|" << endl;
cout << "|-------------------------------|\n" << endl;
system("pause");
}
system("CLS");
goto here;
case 6:
{
exit(0);
}
default:
{
cout << "Invalid choice, Please try again and choose a value between 1-6";
}
system("CLS");
goto here;
}
system("pause");
system("CLS");
return 0;
}
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 2 images