question archive I need help with seeing where I went wrong in my problem, and how to fix it
Subject:Computer SciencePrice: Bought3
I need help with seeing where I went wrong in my problem, and how to fix it. I had a hard time writing this code. Please help me debug it.
Problem:
8.12 LAB: Contact list
A contact list is a place where you can store a specific contact with other associated information such as a phone number, email address, birthday, etc. a program that first takes as input an integer N that represents the number of word pairs in the list to follow. Word pairs consist of a name and a phone number (both strings). That list is followed by a name, and your program should output the phone number associated with that name.
Ex: If the input is:
3 Joe 123-5432 Linda 983-4123 Frank 867-5309
Frank
the output is:
867-5309
Your program must define and call the following function. The return value of GetPhoneNumber is the phone number associated with the specific contact name.
string GetPhoneNumber(vector<string> nameVec, vector<string> phoneNumberVec, string contactName)
Hint: Use two vectors: One for the string names, and the other for the string phone numbers.
Code:
#include <iostream>
#include <vector>
using namespace std;
bool GetPhoneNumber(vector<int> myVec)
{
for (int i = 0; i < myVec.size(); ++i)
{
if (myVec[i] % 2 == 1)
{
return false;
}
}
return true;
}
bool GetPhoneNumber(vector<int> myVec)
{
for (int i = 0; i < myVec.size(); ++i)
{
if (myVec[i] % 2 == 0)
{
return false;
}
}
return true;
}
int main()
{
vector<int> vec;
int n, num,i;
cin >> n;
for (i = 0; i < n; ++i)
{
cin >> num;
vec.push_back(num);
}
if (GetPhoneNumber(vec))
{
cout << "0000000000" << endl;
}
else if (GetPhoneNumber(vec))
{
cout << "0000000000" << endl;
}
else
{
cout << "0000000000" << endl;
}
return 0;