Drowning into an ocean of despair called C++
Ahh in that case use the names of people array[MrX] instead of the standard integer form array[0]
and then just cin the name to a empty variable loop through the array for name matches and cout the matches.
NOTE: I know this is long winded and there is a simpler way to do it, but I cant be arsed to get my C++ book out. :p
a more smplistic way of finding the contents of an array, is to use a for loop:
using namespace std;
int main ()
{
int arr[10];
arr[0]=1;
arr[1]=2;
arr[2]=3;
arr[3]=4;
arr[4]=5;
arr[5]=6;
arr[6]=7;
arr[7]=8;
arr[8]=9;
arr[9]=10;
//search for the number 1;
for(int b=0;b<10;b++)
{
if(arr[b] == 1)
{
cout << "arr[" << b << "] holds the value of 1" << endl;
}
else
{
cout << "arr[" << b << "] doesnt not hold the value of 1" << endl;
}
}
system("pause");
}```
Updated the code…NOW IT DOESN'T WORK!!!!
// 789.cpp : main project file.
#include "stdafx.h" #include "stdlib.h" #include "time.h" #include <sys/types.h> #include <sys/timeb.h> #include <stdio.h> //Returns values to the progra fo the Date function #include <iostream> #include <string.h> using namespace std;
struct employee { char name[30]; char address[35]; char gender; char team; char project[30]; char department; float number_project_completed; float sales_pro;//sales made from the totality of projects float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important char not;//nothing to do with program//to be removed
}; //array decl employee dbase[10]; int i = 1; int choice;
int main() { //nothing to do with program//to be removed
//Declarations for time reading and displaying
char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
struct _timeb tstruct;
cout<<"\n================================================================================";
cout<<" ey3s of cha0s program S.P";
cout<<"\n================================================================================";
// Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
// the operating system is asked to obtain the default value
// for the variable in order to find the time.
//
_tzset();
// Displaying operating system-style date and time. in this case, that of Windows XP
_strtime_s( tmpbuf, 128 );
printf( "\n time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "\n date:\t\t\t\t%s\n", tmpbuf );
cout<<"\n--------------------------------------------------------------------------------";
cout<<"\ Enter Choice.. 1: enter new record...2:do nothing";
cin>>choice;
switch (choice)
{
case 1:
cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
cout<<"Please use only non-capital letters...<<a>> not <<A>>";
cout<<"\n ";
cout << "\n Please enter name: ";
cin >> dbase[i].name;
cout << "\n Please enter address: ";
cin >> dbase[i].address;
//Start of loop aiming at restricting values for "gender"
//While loop
do
{cout<<"\n Enter gender of employee:";
cout<<"Key in M for Male and F for Female: ";
cin>>dbase[i].gender;
} while (dbase[i].gender != 'f'&& dbase[i].gender != 'm');
if (dbase[i].gender == 'm' )
cout<<"\n You entered male";
else
if (dbase[i].gender == 'f')
cout<<"\n You entered Female";
cout << "\n ";
//Start of loop aiming at restricting values for "department"
//While loop
do
{cout<<"\n Enter Department. R: Research D: Development ";
cin>>dbase[i].department;
} while (dbase[i].department != 'd'&& dbase[i].department != 'r');
//Capital letters not considered by program
if (dbase[i].department == 'd' )
cout<<"\n You entered Development Department";
else
if (dbase[i].department == 'r')
cout<<" \n You entered Research Department";
cout<<"\n";
// Start of loop aiming at restricting values for "team"
do {cout<<"\n Enter Team. a: Team Alpha o: Team Omega ";
cin>>dbase[i].team;
} while (dbase[i].team != 'a'&& dbase[i].team != 'o');
if (dbase[i].team == 'a' )
cout<<"\n You entered Team Alpha";
else
if (dbase[i].team == 'o' )
cout<<"\n You entered Team Omega";
cout<<"\n";
cout<<"\n Enter Project the person is responsible of :";
cin>>dbase[i].project;
cout<<"Project name is: "<<dbase[i].project;
cout<<"\n";
cout<<"\n Enter number of projects completed by the employee: ";
cin>>dbase[i].number_project_completed;
cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
cout<<"\n ";
cout<<"\n Input name";
cin>>dbase[i].name;
for(dbase[i] < 11);
{
if
(dbase[i]== dbase[i].name)
{
cout<<"array"<<dbase[i].name<<dbase[i].address;
}
else cout<<"not found";
}
cout<<"\n This shit works!!!!!!!!";
cin>>dbase[i].not;
break;
case 2:
cout<<"\n This **** works!!!!!!!!";
cin>>dbase[i].not;
break;
default:
cout<<"Error!!!! Brain Crash!!";
cin>>dbase[i].not;
}
return 0; }
The only thing I can say about your code is that 'o' != 'O'
(POC)
void CompareOutput()
{
static char lowercaseO = 'o';
static char uppercaseO = 'O';
/* Proof of Concept that 'o' != 'O' */
std::cout<<(int)lowercaseO
<<"\n\r"
<<(int)uppercaseO
<<"\n\r";
/* Solution: Use toupper() or tolower() to
make input conform to one case */
std::cout<<"\n\r"
<<(int)(toupper(lowercaseO))
<<"\n\r"
<<(int)(toupper(uppercaseO))
<<"\n\r";
}
ey3s here:: modified the code..works now..
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include <sys/timeb.h>
#include <stdio.h>
#include <iostream>
//#include <string> to be used later for files i think
using namespace std;
struct employee
{
//different data types
char name[30];
char address[35];
char gender;
char team;
char project[30];
char department;
float number_project_completed;
float sales_pro;//sales made from the totality of projects
float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
char not;//nothing to do with program//to be removed
};
//array declaration
employee dbase[10];
int i = 0; //pointer 1
int x = 0;// pointer 2
int choice;
int main()
{
char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
cout<<"\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
cout<<" ey3s of cha0s program S.P";
cout<<"\n==*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
// Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
// the operating system is asked to obtain the default value
// for the variable in order to find the time.
//
_tzset();
// Displaying operating system-style date and time. in this case, that of Windows XP
_strtime_s( tmpbuf, 128 );
printf( "\n time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "\n date:\t\t\t\t%s\n", tmpbuf );
//selection
cout<<"\n--------------------------------------------------------------------------------";
cout<<"\ Enter Choice... Enter New Record:1 Test:2 ";//test 2 to be rm
cin>>choice;
switch (choice)
{
case 1:
cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
cout<<"Please use only non-capital letters...<<a>> not <<A>>";//problem to be fixed later
cout<<"\n ";
cout << "\n Please enter name: ";
cin >> dbase[i].name;
cout << "\n Please enter address: ";
cin >> dbase[i].address;
//Start of loop aiming at restricting values for "gender"
//While loop [iteration]
do
{cout<<"\n Enter gender of employee:";
cout<<"Key in M for Male and F for Female: ";
cin>>dbase[i].gender;
} while (dbase[i].gender != 'f'&& dbase[i].gender != 'm');
if (dbase[i].gender == 'm' )
cout<<"\n You entered male";
else
if (dbase[i].gender == 'f')
cout<<"\n You entered Female";
cout << "\n ";
//Start of loop aiming at restricting values for "department" [iteration]
//While loop
do
{cout<<"\n Enter Department. r: Research d: Development ";
cin>>dbase[i].department;
} while (dbase[i].department != 'd'&& dbase[i].department != 'r');
//Capital letters not considered by program--2 be fixed LATER but SOON
if (dbase[i].department == 'd' )
cout<<"\n You entered Development Department";
else
if (dbase[i].department == 'r')
cout<<" \n You entered Research Department";
cout<<"\n";
// Start of loop aiming at restricting values for "team" [iteration]
do {cout<<"\n Enter Team. a: Team Alpha o: Team Omega ";
cin>>dbase[i].team;
} while (dbase[i].team != 'a'&& dbase[i].team != 'o');
if (dbase[i].team == 'a')
cout<<"\n You entered Team Alpha";
else
if (dbase[i].team == 'o'&& dbase[i].team == 'O' )
cout<<"\n You entered Team Omega";
cout<<"\n";
cout<<"\n Enter Project the person is responsible of :";
cin>>dbase[i].project;
cout<<"Project name is: "<<dbase[i].project;
cout<<"\n";
cout<<"\n Enter number of projects completed by the employee: ";
cin>>dbase[i].number_project_completed;
cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
cout<<"\n ";
//searching technique -- for statement/loop
char name1[30];
cout<<"\n Input name of employee you wanna search data for: ";
cin>>name1;
for( x=0; x<=i ; x++)
{
if (strcmp(dbase[i].name, name1) == 0)
cout<<"address "<<dbase[i].address;
else cout<<"not found";
}
cout<<"\n This one** works!!!!!!!!";
cin>>dbase[i].not;
break;
case 2:
cout<<"\n This **** works too!!!!!!!!!!";
cin>>dbase[i].not;
break;
default:
cout<<"Error!!!! No such choice available!!";
cin>>dbase[i].not;
}
//end of searching
return 0;
}
//FILE STRUCTURE TO BE DONE```
ey3s here:: modified the code..works now..
#include "stdafx.h"
#include "stdlib.h"
#include "time.h"
#include <sys/timeb.h>
#include <stdio.h>
#include <iostream>
//#include <string> to be used later for files i think
using namespace std;
struct employee
{
//different data types
char name[30];
char address[35];
char gender;
char team;
char project[30];
char department;
float number_project_completed;
float sales_pro;//sales made from the totality of projects
float rank;//an assignment for the renk which the person possese within the company. The smallest number representing the most important
char not;//nothing to do with program//to be removed
};
//array declaration
employee dbase[10];
int i = 0; //pointer 1
int x = 0;// pointer 2
int choice;
int main()
{
char tmpbuf[128], timebuf[26], ampm[] = "AM";//setting AM format
cout<<"\n=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
cout<<" ey3s of cha0s program S.P";
cout<<"\n==*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=";
// Set time zone from TZ (Time Zone) environment variable. If TZ is not set,
// the operating system is asked to obtain the default value
// for the variable in order to find the time.
//
_tzset();
// Displaying operating system-style date and time. in this case, that of Windows XP
_strtime_s( tmpbuf, 128 );
printf( "\n time:\t\t\t\t%s\n", tmpbuf );
_strdate_s( tmpbuf, 128 );
printf( "\n date:\t\t\t\t%s\n", tmpbuf );
//selection
cout<<"\n--------------------------------------------------------------------------------";
cout<<"\ Enter Choice... Enter New Record:1 Test:2 ";//test 2 to be rm
cin>>choice;
switch (choice)
{
case 1:
cout<<"\n [If a statement appears several times, then you have surely made a mistake] \n";
cout<<"Please use only non-capital letters...<<a>> not <<A>>";//problem to be fixed later
cout<<"\n ";
cout << "\n Please enter name: ";
cin >> dbase[i].name;
cout << "\n Please enter address: ";
cin >> dbase[i].address;
//Start of loop aiming at restricting values for "gender"
//While loop [iteration]
do
{cout<<"\n Enter gender of employee:";
cout<<"Key in M for Male and F for Female: ";
cin>>dbase[i].gender;
} while (dbase[i].gender != 'f'&& dbase[i].gender != 'm');
if (dbase[i].gender == 'm' )
cout<<"\n You entered male";
else
if (dbase[i].gender == 'f')
cout<<"\n You entered Female";
cout << "\n ";
//Start of loop aiming at restricting values for "department" [iteration]
//While loop
do
{cout<<"\n Enter Department. r: Research d: Development ";
cin>>dbase[i].department;
} while (dbase[i].department != 'd'&& dbase[i].department != 'r');
//Capital letters not considered by program--2 be fixed LATER but SOON
if (dbase[i].department == 'd' )
cout<<"\n You entered Development Department";
else
if (dbase[i].department == 'r')
cout<<" \n You entered Research Department";
cout<<"\n";
// Start of loop aiming at restricting values for "team" [iteration]
do {cout<<"\n Enter Team. a: Team Alpha o: Team Omega ";
cin>>dbase[i].team;
} while (dbase[i].team != 'a'&& dbase[i].team != 'o');
if (dbase[i].team == 'a')
cout<<"\n You entered Team Alpha";
else
if (dbase[i].team == 'o'&& dbase[i].team == 'O' )
cout<<"\n You entered Team Omega";
cout<<"\n";
cout<<"\n Enter Project the person is responsible of :";
cin>>dbase[i].project;
cout<<"Project name is: "<<dbase[i].project;
cout<<"\n";
cout<<"\n Enter number of projects completed by the employee: ";
cin>>dbase[i].number_project_completed;
cout<<"The employee has acheived "<<dbase[i].number_project_completed<<" projects ";
cout<<"\n ";
//searching technique -- for statement/loop
char name1[30];
cout<<"\n Input name of employee you wanna search data for: ";
cin>>name1;
for( x=0; x<=i ; x++)
{
if (strcmp(dbase[i].name, name1) == 0)
cout<<"address "<<dbase[i].address;
else cout<<"not found";
}
cout<<"\n This one** works!!!!!!!!";
cin>>dbase[i].not;
break;
case 2:
cout<<"\n This **** works too!!!!!!!!!!";
cin>>dbase[i].not;
break;
default:
cout<<"Error!!!! No such choice available!!";
cin>>dbase[i].not;
}
//end of searching
return 0;
}
//FILE STRUCTURE TO BE DONE```
Take a look at std::atoi()
As for your other two questions, I'm not quite sure what you're asking.
No need for atoi(), a simple markupstatic_cast<int>(myCharValue);
will work just fine (assuming he really wants char to int and not an array of characters). Also, C++ has the standard template library for a reason, so why aren't you using std::string etc. As for your other questions, well you'll have to be a bit more specific on what you mean.
Cheers, T-Metal