Feb 17, 2018 at 12:54am UTC
I have a program that is giving me getline errors on certain lines but not all. It also is giving me one or two other errors as well. I have posted my code and others can copy/paste it to work with no problem. I still can't get it to run. I'm using Visual Studio 2017. Anyone have any ideas???
Feb 17, 2018 at 1:34am UTC
Without seeing the code or the errors, there's not much I can say.
Feb 17, 2018 at 4:20am UTC
Last edited on Feb 17, 2018 at 4:23am UTC
Feb 17, 2018 at 11:04am UTC
Here is my code.
#include <iostream>
#include <string.h>
using namespace std;
int index = 0; //variable to hold how many custers are entered
struct Address //Structure for the address.
{
string street;
string city;
string state;
string zipcode;
};
struct Customer //Stucture for the Customer
{
string firstNm, lastNm;
Address busAddr, homeAddr;
};
//Functions
int displayMenu();
Customer getCustomer();
void showCustomer(Customer);
void allCustomers(Customer[]);
Address getAddress();
void findCust(Customer[], int);
int main()
{
Customer cust[100];
while (true)
{
int choice = displayMenu();
switch (choice)
{
case 1:
cust[index] = getCustomer();
index++;
break;
case 2:
allCustomers(cust);
break;
case 3:
findCust(cust, index);
break;
case 4:
cout << "Exit program!!" << endl;
return 0;
break;
default:
cout << "Invald selection!!" << endl;
}
cout << endl;
}
return 0;
}
int displayMenu()
{
//Display menu.
cout << "1. Enter new customer. " << endl;
cout << "2. Display all customers. " << endl;
cout << "3. Display a particular customer. " << endl;
cout << "4. Exit the program. " << endl;
int choice; // User selects the option they want.
cout << "Enter choice: ";
cin >> choice;
cin.ignore();
cout << endl;
return choice; //Return choice displayed.
}
Address getAddress() { // User enters requested information.
Address a;
cout << "Enter Street: ";
getline(cin, a.street);
cout << "Enter City: ";
getline(cin, a.city);
cout << "Enter State: ";
getline(cin, a.state);
cout << "Enter Zip Code: ";
getline(cin, a.zipcode);
return a;
}
Customer getCustomer() // Enter first name, last name and two addresses and return the customer.
{
Customer c;
cout << "Enter First Name: ";
getline(cin, c.firstNm);
cout << "Enter Last Name: ";
getline(cin, c.lastNm);
cout << "Enter Business Address: " << endl;
c.busAddr = getAddress();
cout << "\n Enter Home Address: " << endl;
c.homeAddr = getAddress();
cout << endl;
return c;
}
void showCustomer(Customer c) {
cout << "First Name: " << c.firstNm << endl;
cout << "Last Name: " << c.lastNm << endl;
cout << "Business Address: " << c.busAddr.street << " , " << c.busAddr.city << " , " << c.busAddr.state << " , " << c.busAddr.zipcode << endl;
cout << "Home Address: " << c.homeAddr.street << " , " << c.homeAddr.city << " , " << c.homeAddr.state << " , " << c.homeAddr.zipcode << endl;
}
void allCustomers(Customer cust[]) {
for (int i = 0;i < index; i++) {
showCustomer(cust[i]);
cout << endl;
}
}
void findCust(Customer cust[], int size) {
// Ask user to enter first and last name
string firstName, lastName;
cout << "Enter First Name: ";
getline(cin, firstName);
cout << "Enter Last Name: ";
getline(cin, lastName);
cout << endl;
for (int i = 0; i < size; i++) {
if (cust[i].firstNm == firstName && cust[i].lastNm == lastName) {
showCustomer(cust[i]);
return;
}
}
cout << "Customer not found!" << endl;
}
Feb 17, 2018 at 3:58pm UTC
This has nothing to do with Visual Studio.
You miss an include directive for <string>
Feb 18, 2018 at 9:40pm UTC
I ran the program,
for me the result is clear and i get ;
1. Enter new customer.
2. Display all customers.
3. Display a particular customer.
4. Exit the program.
Enter choice:
Feb 18, 2018 at 9:49pm UTC
If i pursue the program some logical sequences are missing but the program so far is running
So i followed the test and i 'm getting this for the 1st choice;
1. Enter new customer.
2. Display all customers.
3. Display a particular customer.
4. Exit the program.
Enter choice: 1
Enter First Name: bob
Enter Last Name: the ET
Enter Business Address:
Enter Street: deep valley moon
Enter City: saturn's ring
Enter State: Saturn
Enter Zip Code: n/a
Enter Home Address:
Enter Street: crater 223
Enter City:
The program doesn't let me place Business Address neither Home address
So putting aside the missing logics of the program to fullfil the requirement, over my place i get 1 wrong message at
" Customer cust[100]; " ! (int) !
Last edited on Feb 18, 2018 at 9:56pm UTC
Feb 18, 2018 at 10:05pm UTC
Hello Glekker
dev-cpp is good for small program and isn't supported anymore
If anything better would be " ECLIPSE " with " gcc ( MinGW)-compiler "