Code:
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cstring>
#include <cstdlib>
#include <cctype>
using namespace std;
//Info struct is data type
struct info
{
char date[30];
char op[20];
int bthNum;
int trk, bus, pass;
int util, mbike, semi, four;
double total;
};
//functions used to run the program
void getInfo(info[], int);
void fillArray(ifstream, info[], int);
void writeInfo(info[], int);
void main()
{
int choice = 0;
//create new data type - 'info' struct called 'data'
info data[5] = {"","",0,0,0,0,0,0,0,0,0};
//open the input file on disk
ifstream inFile;
inFile.open("C:\\data.dat", ios::in);
if (!inFile.fail())
{
fillArray(inFile, data, 5);
inFile.close();
}
else
{
cout<<"Error finding or creating file 'C: data.dat'"<<endl;
}
writeInfo(data, 5);
}
//Fill function - fills with data from disk
void fillArray(ifstream input, info inputdata[], int size)
{
for(int i=0; i<=size;i++)
{
input.get(inputdata[i].date,30, '#');
input.ignore(1);
input.get(inputdata[i].op, 20,'#');
input.ignore(1);
input>>inputdata[i].bthNum;
input.ignore(1);
input>>inputdata[i].trk;
input.ignore(1);
input>>inputdata[i].bus;
input.ignore(1);
input>>inputdata[i].pass;
input.ignore(1);
input>>inputdata[i].util;
input.ignore(1);
input>>inputdata[i].mbike;
input.ignore(1);
input>>inputdata[i].semi;
input.ignore(1);
input>>inputdata[i].four;
input.ignore(1);
input>>inputdata[i].total;
input.ignore(1);
}
}
//Write function - writes all data to disk
void writeInfo(info data[], int)
{
//open file
ofstream outData;
outData.open("C:\\data.dat", ios::out);
if(!outData.fail())
{
for(int i=0; i<5; i++)
{
outData<<data[i].date<<'#'
<<data[i].op<<'#'
<<data[i].bthNum<<'#'
<<data[i].trk<<'#'
<<data[i].bus<<'#'
<<data[i].pass<<'#'
<<data[i].util<<'#'
<<data[i].mbike<<'#'
<<data[i].semi<<'#'
<<data[i].four<<'#'
<<data[i].total<<endl;
}
outData.close();
}
else
{
cout<<"error opening file"<<endl;
}
}
=============================================
Code:
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <cctype>
#include <iomanip>
using namespace std;
//Info struct is data type
struct info
{
char name[30];
char date[30];
int booth;
int truk, bus, pass, pasv, bike, semi, four;
double total;
};
//functions used to run the program
void menu(info data[], int size);
void getInfo(info[], int);
char* checkstring(char[30], char*);
int VehicleInput(char[5], int&);
void fillArray(ifstream, info[], int);
void writeInfo(info[], int);
void getReport(info data[], int size);
void exit();
void main()
{
int choice = 0;
//create new data type - 'info' struct called 'data'
info data[5] = {"","",0,0,0,0,0,0,0,0,0};
//open the input file on disk
ifstream inFile;
inFile.open("C:\\info.tb", ios::in);
if (!inFile.fail())
{
fillArray(inFile, data, 5);
inFile.close();
}
else
{
cout << "Error finding or creating file C:info.tb" << endl;
}
menu(data, 5);
writeInfo(data, 5);
}
//Fill function - fills with data from disk
void fillArray(ifstream input, info inputdata[], int size)
{
for(int i=0; i<=size;i++)
{
input.get(inputdata[i].date,30, '#');
input.ignore(1);
input.get(inputdata[i].name, 20,'#');
input.ignore(1);
input>>inputdata[i].booth;
input.ignore(1);
input>>inputdata[i].truk;
input.ignore(1);
input>>inputdata[i].bus;
input.ignore(1);
input>>inputdata[i].pass;
input.ignore(1);
input>>inputdata[i].pasv;
input.ignore(1);
input>>inputdata[i].bike;
input.ignore(1);
input>>inputdata[i].semi;
input.ignore(1);
input>>inputdata[i].four;
input.ignore(1);
input>>inputdata[i].total;
input.ignore(1);
}
}
//Write function - writes all data to disk
void writeInfo(info data[], int)
{
//open file
ofstream outData;
outData.open("C:\\info.tb", ios::out);
if(!outData.fail())
{
for(int i=0; i<5; i++)
{
outData << data[i].date << '#'
<< data[i].name << '#'
<< data[i].booth << '#'
<< data[i].truk << '#'
<< data[i].bus << '#'
<< data[i].pass << '#'
<< data[i].pasv << '#'
<< data[i].bike << '#'
<< data[i].semi << '#'
<< data[i].four << '#'
<< data[i].total <<endl;
}
outData.close();
}
else
{
cout << "error opening file" << endl;
}
}
//Get Data function - prompts user for their input data
void getInfo(info data[], int size)
{
int num = 0;//booth number entered by user
char count[5];//stores input for vehic count
float charge = 0;//charge amount entered by user
double bthTotal = 0;//total correct charges of booth
int b = 0;//vehic count converted to int
char idate[30], name[30];//date and name input
char contin = 'Y';//loop control
char addMore = 'Y';//loop control
char vehic;//vehic type
char ok = 'Y';//loop control
char totalTest[10];//stores test input for
char ch = 'N';//loop control
cout << endl << endl << endl;
//gets todays date
checkstring(idate, "Please enter todays date: "); //send question and variable to error-checking function
cout << endl;
//gets the name of the operator
checkstring(name, "Please enter your name: "); //send question and variable to error-checking function
cout << endl;
//copies the date and operator to each booth
for (int i=0; i<5;i++)
{
strcpy(data[i].date, idate);
strcpy(data[i].name, name);
}
do{
char sel[1];
//gets first booth number
cout<<"Please enter the booth number [1-5] : ";
cin.ignore(100,'\n');
cin>>sel;
int a = atoi(sel);
num = a;
//Checks for valid integer
while ((a<1)||(a>5))
{ cout<<endl;
cout<<"Please enter a valid integer [1-5] :"<<endl<<endl;
cout<<"Booth Number -> ";
cin.ignore(100,'\n');
cin>>sel;
a=atoi(sel);
num = a;
}
cout<<endl<<endl;
data[num-1].booth = num;
//displays vehicle types
do{
cout<<" ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ VEHICLE TYPES ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"<<endl;
cout<<" Û TYPE CHARGE Û"<<endl;
cout<<" Û Û"<<endl;
cout<<" Û Û"<<endl;
cout<<" Û M = Motorbike ..... ..... ..... [$1:20] Û"<<endl;
cout<<" Û P = Passenger Vehicle ..... ..... [$2:20] Û"<<endl;
cout<<" Û U = Pass.Vehicle + Trailer (ute) [$2:40] Û"<<endl;
cout<<" Û F = 4 Wheeled Drive ..... ..... [$2:50] Û"<<endl;
cout<<" Û B = Bus ..... ..... ..... ..... [$4:20] Û"<<endl;
cout<<" Û T = Truck ..... ..... ..... ..... [$5:00] Û"<<endl;
cout<<" Û S = Semi Trailer ..... ..... ..... [$6:20] Û"<<endl;
cout<<" Û Û"<<endl;
cout<<" Û X = Exit Data Entry Û"<<endl;
cout<<" Û Û"<<endl;
cout<<" ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ"<<endl<<endl;
do{
//prompt for vehicle type
cout<<endl<<endl;
cout<<data[num-1].name;
cout<<", please enter your vehicle type : ";
cin.ignore(100,'\n');
cin>>vehic;
vehic = toupper(vehic);
cout<<endl;
//check type is valid
if((vehic !='T')&&(vehic !='B')&&(vehic !='F')
&&(vehic !='P')&&(vehic !='M')&&(vehic !='S')
&&(vehic !='U')&&(vehic !='X'))
{
cout<<"Invalid vehicle type"<<endl;
ok = 'N';
}
else
{
ok = 'Y';
}
}while(ok != 'Y');
switch(vehic)
{
case 'T':
if(data[num-1].truk<2000)
{
//prompts for number of vehicle
do{
cout << "Please enter the number of Trucks [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);//converts to int
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
//checks if total in booth will add beyond 2000
if((data[num-1].truk + b)<2001)
{
data[num-1].truk = data[num-1].truk + b;
}
else
{
cout << "Cannot add that many trucks" << endl << endl;
cout << "A maximum of 2000 trucks can be added" << endl << endl;
menu(data, 5);
}
}
//if total entered is above 2000 - error message
else
{
cout << " The total number of trucks exceeds 2000, no more trucks can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'B':
if(data[num-1].bus<2000)
{
do{
cout << "Please enter the number of Buses [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].bus + b)<2001)
{
data[num-1].bus = data[num-1].bus + b;
}
else
{
cout << "Cannot add that many buses" << endl << endl;
cout << "A maximum of 2000 buses can be entered" << endl << endl;
menu(data, 5);
}
}
else
{
cout << "The total number of buses exceeds 2000, no more buses can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'F':
if(data[num-1].four<2000)
{
do{
cout << "Please enter the number of 4 wheeled drives [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].four + b)<2001)
{
data[num-1].four = data[num-1].four + b;
}
else
{
cout << "Cannot add that many 4 wheeled drives"<<endl<<endl;
cout << "A maximum of 2000 4 wheeled drives can be entered"<<endl<<endl;
menu(data, 5);
}
}
else
{
cout << "Total number of 4 wheeled drives exceeds 2000, No more 4 wheeled drives can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'P':
if(data[num-1].pass<2000)
{
do{
cout << "Please enter the number of Passenger vehicles [1 - 2000] :";
cin.ignore(100,'\n');
cin>>count;
b = atoi(count);
cout<<endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].pass + b)<2001)
{
data[num-1].pass = data[num-1].pass + b;
}
else
{
cout << "Cannot add that many passenger vehicles" << endl;
cout << "A maximum of 2000 passenger vehicles can be entered" << endl << endl;
menu(data, 5);
}
}
else
{
cout << "Total number of passenger vehicles exceeds 2000, No more passenger vehicles can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'M':
if(data[num-1].bike<2000)
{
do{
cout << "Please enter the number of Motorbikes [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].bike + b)<2001)
{
data[num-1].bike = data[num-1].bike + b;
}
else
{
cout << "Cannot add that many motorbikes" << endl << endl;
cout << "A maximum of 2000 motorbikes can be entered" << endl << endl;
menu(data, 5);
}
}
else
{
cout << "Total number of motorbikes exceeds 2000, No more motorbikes can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'S':
if(data[num-1].semi<2000)
{
do{
cout << "Please enter the number of Semi Trailers [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].semi + b)<2001)
{
data[num-1].semi = data[num-1].semi + b;
}
else
{
cout << "Cannot add that many semi trailers" << endl << endl;
cout << "A maximum of 2000 semi trailers can be entered" << endl << endl;
menu(data, 5);
}
}
else
{
cout << "Total number of semi trailers exceeds 2000, No more semi trailers can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'u': case 'U':
if(data[num-1].pasv<2000)
{
do{
cout << "Please enter the number of Passenger Vehicles with Trailers [1 - 2000] :";
cin.ignore(100,'\n');
cin >> count;
b = atoi(count);
cout << endl;
VehicleInput(count, b);
}while(ok != 'Y');
if((data[num-1].pasv + b)<2001)
{
data[num-1].pasv = data[num-1].pasv + b;
}
else
{
cout << "Cannot add that many passenger vehicles with trailers" << endl << endl;
cout << "A maximum of 2000 passenger vehicles with trailers can be entered"<< endl << endl;
menu(data, 5);
}
}
else
{
cout << "Total number of passenger vehicles with trailers exceeds 2000, No more passenger vehicles with trailers can be added to this booth." << endl << endl;
menu(data, 5);
}
break;
case 'x': case 'X':
menu(data, 5);
break;
//default should never be accessed
default:
cout << "An error has occured." << endl << endl;
menu(data, 5);
}
//prompt user for choice
do
{
cout << endl << endl;
cout << "Do you wish to add another type of vehicle to this booth? [Y / N] : ";
cin.ignore(100,'\n');
cin >> ch;
ch = toupper (ch);
//check input
if((ch !='Y')&&(ch !='N'))
{
cout << endl << endl;
cout << "Invalid input " << endl;
ok = 'N';
}
else
{
ok = 'Y';
cout << endl << endl << endl;
}
}while(ok != 'Y');
}while(ch == 'Y');
//Prompts for amount taken at this booth
cout << "Please enter the total amount taken for this booth :";
cin.ignore(100,'\n');
cin >> totalTest;
double c = atof(totalTest);
//Checks for valid integer
while (c<=0)
{ cout << endl;
cout << "Please enter a valid integer." << endl << endl;
cout << "Amount -> ";
cin.ignore(100,'\n');
cin >> totalTest;
c=atof(totalTest);
}
//put total taken into booth total
data[num-1].total = c;
//calculate correct total for the booth
bthTotal = (data[num-1].bus * 4.20)+(data[num-1].truk * 5.50)
+(data[num-1].pass * 2.20)+(data[num-1].pasv * 2.40)
+(data[num-1].bike * 1.20)+(data[num-1].semi * 6.20)
+(data[num-1].four * 2.50);
//display message stating whether charges are correct
if(bthTotal==data[num-1].total)
{
cout << endl << endl << endl;
cout<<'\t'<<'\t'<<"- CORRECT CHARGES -"<<endl<<endl;
}
else
{
cout << endl << endl << endl;
cout<<'\t'<<'\t'<<" - INCORRECT CHARGES - "<<endl<<endl;
cout<<setiosflags(ios::fixed | ios::showpoint);
//set to 2 decimal places
cout << setprecision(2);
cout<<'\t'<<'\t'<<"The correct charges for this booth are : $" << bthTotal << endl << endl << endl;
}
//prompt user - add vehicles to another booth
do
{
cout << endl << endl;
cout << "Do you wish to add information to another booth? [Y / N] : ";
cin.ignore(100,'\n');
cin >> addMore;
addMore = toupper (addMore);
cout << endl << endl;
//check input
if((addMore !='Y')&&(addMore !='N'))
{
cout << endl << endl;
cout << "Invalid input " << endl << endl;
ok = 'N';
}
else
{
ok = 'Y';
}
}while(ok != 'Y');
}while(addMore == 'Y');
//return to main
menu(data, 5);
}
//Menu function - to display menu for user to select from
void menu(info data[], int size)
{
char sel[1];
int b = 0;
cout << endl << endl;
cout << " Toll Booth Magic: Main Menu" << endl;
cout << endl;
cout << " ßÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛß" << endl;
cout << " Û²° °²Û " << endl;
cout << " Û° °Û " << endl;
cout << " Û Please Select an Option: Û " << endl;
cout << " Û-------------------------------------------Û " << endl;
cout << " Û 1. Enter Booth Data Û " << endl;
cout << " Û 2. View Booth Report Û " << endl;
cout << " Û 3. Exit Program Û " << endl;
cout << " Û Û " << endl;
cout << " Û° °Û " << endl;
cout << " Û²° °²Û " << endl;
cout << " ÜÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÜ" << endl;
cout << '\t' << '\t' << "Your Selection -> ";
cin>>sel;
b = atoi(sel);
do{
//Checks for valid integer
if(b<=0)
{ cout<<endl;
cout<<'\t'<<'\t'<<"Please enter a valid integer [1 - 3]."<<endl<<endl;
cout<<'\t'<<'\t'<<"Your Choice -> ";
cin>>sel;
b=atoi(sel);
}
else
{
if((b!=1)&&(b!=2)&&(b!=3))
{
cout<<endl;
cout<<'\t'<<'\t'<<"Please enter a valid integer [1 - 3]."<<endl<<endl;
cout<<'\t'<<'\t'<<"Your Choice -> ";
cin>>sel;
b=atoi(sel);
}
}
}while((b!=1)&&(b!=2)&&(b!=3));
if(b == 1)
{
getInfo(data, 5);
}
else
if(b == 2)
{
getReport(data, 5);
}
else
if(b == 3)
{
exit();
}
cout << endl;
}
//Report function - displays report to screen,
void getReport(info data[], int size)
{
int i = 0;//loop control
char choice = 'Y';//loop control
int totalvehic = 0;//total vehicle count
double expectedCharges = 0;//correct charges for booths
//stores totals of all booths
double chargesT = 0;
double chargesB = 0;
double chargesM = 0;
double chargesP = 0;
double chargesU = 0;
double chargesS = 0;
double chargesF = 0;
int totaltruk = 0;
int totalbus = 0;
int totalpass = 0;
int totalpasv = 0;
int totalbike = 0;
int totalsemi = 0;
int totalfour = 0;
double receivedCharges = 0;
//calculates the totals
for(i=0;i<5;i++)
{
expectedCharges = 0;
chargesT = chargesT +(data[i].truk * 5.00);
expectedCharges = chargesT + expectedCharges;
chargesB = chargesB +(data[i].bus * 4.20);
expectedCharges = chargesB + expectedCharges;
chargesP = chargesP +(data[i].pass * 2.20);
expectedCharges = chargesP + expectedCharges;
chargesU = chargesU +(data[i].pasv * 2.40);
expectedCharges = chargesU + expectedCharges;
chargesM = chargesM +(data[i].bike * 1.20);
expectedCharges = chargesM + expectedCharges;
chargesS = chargesS +(data[i].semi * 6.20);
expectedCharges = chargesS + expectedCharges;
chargesF = chargesF +(data[i].four * 2.50);
expectedCharges = chargesF + expectedCharges;
totaltruk = totaltruk + data[i].truk;
totalbus = totalbus + data[i].bus;
totalpass = totalpass + data[i].pass;
totalpasv = totalpasv + data[i].pasv;
totalbike = totalbike + data[i].bike;
totalsemi = totalsemi + data[i].semi;
totalfour = totalfour + data[i].four;
receivedCharges = receivedCharges + data[i].total;
}
//total count of vehicles
totalvehic = (totalbike + totalpass + totalpasv + totalfour + totaltruk + totalbus + totalsemi);
//total count of correct charges
expectedCharges = ((totalbike * 1.2) + (totalpass * 2.2) + (totalpasv * 2.4) + (totalfour * 2.5) + (totaltruk * 5.5) + (totalbus * 4.2) + (totalsemi * 6.2));
double diff = (receivedCharges - expectedCharges);
//displays report
cout << "ÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜÜ" << endl;
cout << "ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ²²²°°°° FINAL REPORT °°°°²²²ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ" << endl;
cout << "Ûßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß" << endl;
cout << "Û Date: " << data[1].date << ", Operator: " << data[1].name << endl;
cout << "Û " << endl;
cout << "Û TOTAL VEHICLES °°°²²ÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛÛ" << endl;
cout << "Û Û" << endl;
cout << "Û Totals Money Expected Û" << endl;
cout << "Û °²ÛÛ²° °°°²²²ÛÛÛ²²²°°° Û" << endl;
cout << "Û Total Motorbikes: " << setw(12) << totalbike << setw(17) << chargesM << setw(10) << "Û" << endl;
cout << "Û Total Passenger vehicles: " << setw(12) << totalpass << setw(17) << chargesP << setw(10) << "Û" << endl;
cout << "Û Total Pass. with Trailers: " << setw(12) << totalpasv << setw(17) << chargesU << setw(10) << "Û" << endl;
cout << "Û Total Four Wheeled Drives: " << setw(12) << totalfour << setw(17) << chargesF << setw(10) << "Û" << endl;
cout << "Û Total Trucks: " << setw(12) << totaltruk << setw(17) << chargesT << setw(10) << "Û" << endl;
cout << "Û Total Buses: " << setw(12) << totalbus << setw(17) << chargesB << setw(10) << "Û" << endl;
cout << "Û Total Semi Trailers: " << setw(12) << totalsemi << setw(17) << chargesS << setw(10) << "Û" << endl;
cout << "Û__________________________________________________________________Û" << endl;
cout << "Û BOOTH TOTALS Totals Û" << endl;
cout << "Û Û" << endl;
cout << "Û Total Number of Vehicles: " << setw(9) << totalvehic << setw(3) << "Û" << endl;
cout << "Û Total Charges Received for all Vehicles: " << setw(9) << receivedCharges << setw(3) << "Û" << endl;
cout << "Û Total Charges Expected for all Vehicles: " << setw(9) << expectedCharges << setw(3) << "Û" << endl;
cout << "Û Surp/Def: " << setw(9) << diff << setw(3) << "Û" << endl;
cout << "ßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßßß" << endl;
//prompts user to leave report screen
do{
cout << "Exit report [Y / N] : ";
cin.ignore(100,'\n');
cin >> choice;
choice = toupper(choice);
//checks input
while((choice!='Y')&&(choice!='N'))
{
cout << endl << endl;
cout << "An invalid entry has been made." << endl;
cout << "Please enter your choice again." << endl;
cout << "Exit report [Y / N] : ";
cin.ignore(100,'\n');
cin >> choice;
choice = toupper(choice);
cout << endl << endl;
}
if(choice == 'N')
{
cout << endl;
}
}while(choice !='Y');
//returns to main
menu(data, 5);
}
//Exit function - quits "Toll Booth Magic"
void exit()
{
cout << endl;
cout << "Closing Toll Booth Magic" << endl;
}
//Vehicle Entry Validation Function
int VehicleInput(char* count, int& b)
{
char ok = 'Y';//loop control
b = atoi(count);//converts to int
cout << endl;
while((b > 2000)||(b <= 0))
{
ok = 'N';
cout << "An invalid entry has been made." << endl << endl;
cout << "Number [1 - 2000] -> ";
cin.ignore(100,'\n');
cin >> count;
b=atoi(count);
cout << endl;
}
ok = 'Y';
return b;
}
char* checkstring(char* working, char* question) //function to check that string input is valid
{
int check = 0; //control
cout << question; //outputs question
cin.ignore(100,'\n');
cin >> working;
while (check == 0)
{
string sData = working; //sets string to work with from working
int nStringLength = sData.length( ); //sets nStringlenght to the lendth of sData
if ((nStringLength < 4) || (nStringLength >= 30)) //error checking
{
check = 0;
cout << "Invalid input. " << question << endl;
cin.ignore(100,'\n');
cin >> working;
cout << endl;
}
else
{
check = 1;
return working; //returns valid string
}
}
check = 1;
return working; //this should never be reached as check is initialised to 0
}
If someone can tell me what is causing this, I will love you forever. I am already extremely grateful for what this board has helped me with so far.