I'm attempting a logical comparison at an element in a char-array based on index number but my compiler says illegal comparison. Any ideas about what's going on?
#include <iostream>
#include <cstring>
#include <iomanip>
#include <fstream>
using namespace std;
ofstream MyFile("Assignmentfile.txt");
int userno;
char name[16];
char lastname[16];
char address[51];
char cellno[14];
char landlineno[12];
int sent;
void userinput();
void searchfunc();
void deletecontact();
void displaycontact();
void modifycontact();
void sortcontact();
void findcontact();
int main()
{
MyFile<<"First Name Last Name Address Cell Number Landline Number"<<endl;
userinput();
return 0;
}
void userinput()
{
{
cout<<"Would you like to enter a new contact? (1/0) ";
cin>>sent;
while (sent==1)
{
cout<<"Enter Name: ";
cin>>name;
MyFile<<left<<setw(16)<<name<<"|";
cout<<"Enter Last name: ";
cin>>lastname;
MyFile<<left<<setw(16)<<lastname<<"|";
cout<<"Enter Address: ";
cin>>address;
MyFile<<left<<setw(51)<<address<<"|";
cout<<"Enter Cell Number: ";
cin>>cellno;
if (cellno[0]=="+")
{
cout<<"Enter Cell number again starting with +92"; // The problem appears here //
}
MyFile<<left<<setw(14)<<cellno<<"|";
cout<<"Enter Landline Number: ";
cin>>landlineno;
MyFile<<left<<setw(12)<<landlineno<<endl;
cout<<endl;
cout<<"Would you like to enter a new contact? (1/0) ";
cin>>sent;
}
MyFile.close();
}
}
The program must be able to write and read from a text file. It can create contacts, modify them, delete them, sort them and search through them. The problem is that the cell number must start from "+92"
i.e "+923454356568"
. I thought that if (cellno[0]=="+")
and so on would work.
I cannot use strings and only have to rely on character type arrays. Using strings would make all of this a piece of cake.
Below is the assignment I wish to complete.