Hey I am almost finished my code but i cant see why in the voucher print function its not displaying cost near hire cost anyone else me out ?

#include<iostream>
#include<iomanip>
#include<conio.h>
#include<string>
#include<windows.h>

using namespace std;

void Intro();
void NameValidation(string name);
bool LicenseValid(string license);
bool CreditCardValidation(string creditcard);
bool AgeValidation(string age);
bool ExpDate(string carddate );
//using & to get the multiple values needed for report from voucher function
void VoucherPrint(string address, string creditcard, string license, double& grossrev, double& totaldiscount, double& netrev ,string addrivers,string age,unsigned short &rentday,int voucher, string name,string cartype,string daysamount,string insurancetype,char childseat,char gps);
bool AmountDay(string daysamount);
bool AddingDriver(string addrivers);
void gotoxy(short x, short y);
void StartMenu(bool choice, string cartype, unsigned short rentday, char car);
void Report(signed short counter, signed short gpshire,  signed short childsearhire, double grossrev, double totaldiscount,  double netrev);

//naming functions 
int main(){
    char goagain=' ';
    double grossrev = 0.00, totaldiscount = 0.00, netrev = 0.00;
    unsigned short counter = 0, gpshire = 0, childseathire = 0, rentday = 0, voucher = 1;
    do{
        char car = ' ', gps = ' ', childseat = ' ';
        bool choice = true;
        string name = " ", license = " ", age = " ", carddate = " ", cartype = " ", daysamount = " ", insurancetype = " ", addrivers = " ", address = " ";
        double extrascost = 0;
        //Variable declartions above
        system("Color 1F");// setting color To dark blue background and white writing 
        if(goagain == ' ')//has the intro program opening screen only appear the first time round as once gone through is either y or n
            Intro();
        Sleep(1500);
        system("CLS");
        StartMenu(choice, cartype, rentday, car);
        //start of taking in name section see function namevalidation
        NameValidation( name );
        //end of name taking section see function for details
        //start of address taking section
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Customer Address : ";
        cin >> address;
        while(address.length() > 15 ) 
        {
            cout <<"Must be under 15 characters"<< endl;
            Sleep(1500);
            system("CLS");
            cout << setw(50) <<"Magnificent Car Hire"<< endl;
            cout <<"Customer Address : ";
            cin >> address;
        }
        //end of address taking section used while loop to set max on size and repeat till address is beneath max
        system("CLS");
        //start of age taking section
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Customer Age : ";
        cin >> age;
        AgeValidation(age);
        //end of age taking section
        system("CLS");
        //start of licence no taking section
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"licence number : ";
        cin >> license;
        LicenseValid( license );
        //end of licence taking section using the licencevalid function in while loop see function for details
        system("CLS");
        //start of credit card validation 
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        string creditcard; 
        cout <<"Please enter in a 16 digit credit card number "<< endl;
        cout <<"with a space or - after every 4 digits : "<< endl;
        cin.ignore();
        getline(cin, creditcard);
        CreditCardValidation( creditcard );
        //end of creditcard no validation using function in while loop see function for details
        system("CLS");
        //start of expdate validation 
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Card Exp Date : ";
        cin >> carddate;
        ExpDate(carddate);
        //end of exp date validation see function for details
        system("CLS");cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Days Hire required for :";
        cin >> daysamount;
        AmountDay( daysamount);
        while( !AmountDay(daysamount) )
        {
            cout <<"Not valid number of days";
            Sleep(1500);
            system("CLS");
            cout << setw(50) <<"Magnificent Car Hire"<<endl;
            cout <<"Days Hire required for :";
            cin >> daysamount;
        }
        //end of amount of days validation see function for details
        system("CLS");
        //start of checking insurance section 
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"What insurance type of insurance (CDW) for collision damage waver "<< endl;
        cout <<"or (fully) for fully comprehensive insurance :"<< endl;
        cin >> insurancetype;
        while( insurancetype != "CDW" && insurancetype != "fully" )
        {
            system("CLS");
            cout << setw(50) <<"Magnificent Car Hire"<< endl;
            cout <<"What insurance type of insurance (CDW) for collision damage waver "<< endl;
            cout <<"or (fully) for fully comprehensive insurance :"<< endl;
            cin >> insurancetype;
        }
        //end of insurance checking section while loop to continue until required data input
        system("CLS");
        //start of additional driver section
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"How many additional drivers? :";
        cin >> addrivers;
        //end of additional driver section see function for details
        system("CLS");
        //start of car seat checking section 
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout << "Childseat required? Y/N :";
        cin >> childseat;
        if( childseat == 'Y' || childseat == 'y' )
                childseathire += 1;
        while( childseat != 'Y' && childseat != 'N' )
        {
            cout <<"Must be a captial Y/N";
            Sleep(1500);
            system("CLS");
            cout << setw(50) <<"Magnificent Car Hire"<< endl;
            cout <<"Childseat required? Y/N :";
            cin >> childseat;
        }
        //end of carseat checking section using while loop to keep going untill correct input type entered
        system("CLS");
        //start of gps checking section
        cout << setw(50) << "Magnificent Car Hire"<< endl;
        cout <<"GPS required? Y/N :";
        cin >> gps;
        if( gps == 'Y' )
                gpshire += 1;
        while( gps != 'Y' && gps != 'N' )
        {
            cout << "Must be a captial Y/N";
            Sleep(1500);
            system("CLS");
            cout <<"GPS required? Y/N :";
            cin >> gps;
            system("CLS");
        }
        //end of gps checking secion using while loop to keep going untill correct input type entered
        system("CLS");
        //calling voucher printing function to display voucher see function for details
        VoucherPrint(address, creditcard, license, grossrev, totaldiscount, netrev, addrivers, age, rentday, voucher, name, cartype, daysamount, insurancetype, childseat, gps);
        cout <<"Would you like to process another customer? Y/N";
        cin >> goagain;
        while( goagain != 'Y' && goagain != 'y' && goagain != 'N' && goagain != 'n' )
        {
            cout << "Not valid please enter Y or N ";
            Sleep(1500);
            system("CLS");
            cout <<"Would you like to process another customer? Y/N";
            cin >> goagain;
        }
        //program ending displays the below report 
    system("CLS");  
    counter = counter + 1;  
    voucher++;
    }while( goagain != 'N' && goagain != 'n' );
    Report( counter, gpshire,  childseathire,  grossrev, totaldiscount,  netrev);
    return  0;
}
void StartMenu(bool choice, string cartype, unsigned short rentday, char car)
{//function for printing out the start menu and taking in the users choice to a switch statement used char for error handling
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout << setw(65) <<"________________________________________________"<< endl;
        cout << setw(65) <<"| Car Type             |  Cost of Hire per day |"<< endl;
        cout << setw(65) <<"|----------------------|-----------------------|"<< endl;
        cout << setw(65) <<"| 1) Economy           |  EUR14                |"<< endl;
        cout << setw(65) <<"|----------------------|-----------------------|"<< endl;
        cout << setw(65) <<"| 2) Compact           |  EUR17                |"<< endl;
        cout << setw(65) <<"|----------------------|-----------------------|"<< endl;
        cout << setw(65) <<"| 3) Intermediate      |  EUR23                |"<< endl;
        cout << setw(65) <<"|----------------------|-----------------------|"<< endl;
        cout << setw(65) <<"| 4) Premium           |  EUR26                |"<< endl;
        cout << setw(65) <<"|----------------------|-----------------------|"<< endl<< endl;
        //printed table to select car and price of car from
        cout << setw(75) <<"Please select which car you would like from menu above (1, 2, 3 or 4) :";
        cin >> car;
        while( choice==true )
        {
            switch(car)
            {
                case '1':rentday=14; choice=false; cartype="Economy"; break;
                case '2':rentday=17; choice=false; cartype="Compact"; break;
                case '3':rentday=23; choice=false; cartype="Intermediate"; break;
                case '4':rentday=26; choice=false; cartype="Premium"; break;
                default:cout << setw(41) << "Not 1, 2, 3 or 4 please enter again :"; cin >> car; choice=true; break;
            }
        }
}
void Report(signed short counter, signed short gpshire,  signed short childseathire, double grossrev, double totaldiscount,  double netrev)
{//printing the final report after user asks to end program 
    cout <<"DAILY REPORT "<<endl;
    cout <<"The number if cars that were hired :"<< counter << endl;
    cout <<"The number of gps system that were hired :"<< gpshire << endl;
    cout <<"The number of baby seats that were hired :"<< childseathire << endl;
    cout <<"The gross revenue generated :"<< grossrev << endl;
    cout <<"The total discount :"<< totaldiscount << endl;
    cout <<"The net revenue generated :"<< netrev << endl;    
    getch();
}
void NameValidation(string name)//runs code to verify name doesnt have more than 1 - or ' and is a letter will return true from function
{
    int k, count = 0, count2 = 0;
    bool check = true;
    system("CLS");
    cout << setw(50) << "Magnificent Car Hire"<< endl;
    cout <<"Customer Name : ";
    cin.ignore();
    getline(cin, name );
        for( int i = 0; i<name.length(); i++ )
        {
            if( name.at(i) == '-' )
                count += 1; 
            else if ( name.at(i) == '\'' )
                count2 += 1;
            while( !(isalpha(name.at( i ))) && name.at(i)!=' ' && name.at(i) != '-' && name.at(i) != '\'' || count > 1 || count2 > 1 )
            {
                cout <<"sorry not valid please retry "<< endl;
                cout <<"Customer name :";
                getline(cin, name);
            }
        }
    system("CLS");
}
bool LicenseValid(string license)//licence function insures is always 9 long first being digits and last 4 characters
{
   if ( license.length() != 9) 
     return false;
   for ( unsigned short index = 0; index <5; ++index )
   { 
      if( !isdigit(license[index]) )
        return false;
   }

   for ( unsigned short index = 5; index <9; ++index )
   {    
       if( !isalpha(license[index]) )
          return false;
   }
   return true;
   while ( !LicenseValid(license) )
   {
        cout <<"Sorry please re-enter licence should be 9 characters"<<endl<<"first 5 are numbers last 4 are Letters "<< endl;
        Sleep(1500);
        system("CLS");
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"licence number : ";
        cin >> license;
   }
}
bool CreditCardValidation(string creditcard)//checking to make sure sections are 1-4 6-9 11-14 16-19  are all digits after its check intotal it equals 19 chars long
    //also makes sure that 5 + 10 + 15 are equal a space or -
{
    if( creditcard.length()!=19 )
        return false;
    for( int i=0; i < 4; i++ )
    {
        if( !isdigit(creditcard[i]) )
            return false;
    }
    for( int i=5; i < 9; i++ )
    {
        if( !isdigit(creditcard[i]) )
            return false;
    }
    for( int i=10; i < 14; i++ )
    {
        if( !isdigit(creditcard[i]) )
            return false;
    }
    for( int i=15; i < 19;i++ )
    {
        if( !isdigit(creditcard[i]) )
            return false;
    }
    if(creditcard[4] != '-' && creditcard[4] != ' ' || creditcard[9] != '-' && creditcard[9] != ' ' || creditcard[14] != '-' && creditcard[14] != ' ' )
        return false;
    return true;
    while( !CreditCardValidation(creditcard) )
    {
        cout <<"Not valid credit card number please retry :";
        Sleep(1500);
        system("CLS");
        cout <<setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Please enter in a 16 digit credit card number "<< endl;
        cout <<"with a space or - after every 4 digits :"<< endl;
        cin.ignore();
        getline(cin, creditcard);
    }
}
bool AgeValidation(string age)//age function insures that customer is not under 18 
{
    if( age.length()!=2 )
    {
        cout<<"Not valid age format i.e 18"<<endl;
        return false;
    }
    for( int i =0; i<age.length() ;i++ )
    {
        if( !isdigit(age[i]) )
        {
            cout<<"Not a number"<<endl;
            return false;
        }
    }
    if ( stoi(age) < 18 )
    {
        cout<<"Too young to Hire car";
        return false;
    }
    else
        return true;
    while( !AgeValidation(age) )
    {
        Sleep(1500);
        system("CLS");
        cout << setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Customer Age : ";
        cin >> age;
    }
}
bool ExpDate(string carddate )//makes sure that char 1-2 are digit and doesnt go over 12 for months 
//and char 3 is equal to / and char 4-5 are digits
{
    if(carddate[0] == '1' && carddate[1] != '0' || carddate[1] != '1' || carddate[1] != '2' )
        return false;
    if( carddate.length() != 5 )
        return false;
    for( int i=0; i < 2; i++ )
    {
        if( !isdigit(carddate[i]) )
            return false;
    }
    if( carddate[2] != '/' )
        return false;
    for(int i=3; i < 5; i++ )
    {
        if( !isdigit(carddate[i]) )
            return false;
    }
    return true;
    while( !ExpDate(carddate) )
    {
        cout <<"Not valid Date ";
        Sleep(1500);
        system("CLS");
        cout <<setw(50) <<"Magnificent Car Hire"<< endl;
        cout <<"Card Exp Date :";
        cin >> carddate;
    }
}
void VoucherPrint(string address,string creditcard,string license,double& grossrev,double& totaldiscount, double& netrev ,string addrivers,string age,unsigned short &rentday,int voucher, string name,string cartype,string daysamount,string insurancetype,char childseat,char gps)
{
    //prints out voucher for program
    bool option = true;
    int costinsur = 0, extra = 0;
    double discount = 0.0, cost = 0.0;
    cout <<"MAGNIFICENT CAR HIRE "<< setw(55) <<"VOUCHER #:"<< setw(4) << setfill('0') << voucher;
    cout <<endl;
    cout <<setfill(' ');
    cout <<"Customer Details:"<< setw(15) <<"Name:"<<"          "<< name << endl;
    cout << setw(35) <<"Address:"<<"          "<< address << endl;
    cout << setw(42) <<"Licence Number:"<< setw(19) << license << endl;
    cout << setw(47) <<"Credit Card Details:"<< setw(20) <<"XXXX XXXX XXXX "<< creditcard.substr(15,19) << endl << endl;
    cout <<"Car Details:"<<setw(24)<<"Car Type:"<< setw(23) << cartype << endl;
    cout << setw(42) <<"Number of Days:"<<"       "<< daysamount << endl;
    cout << setw(42) <<"Insurance Type:"<<"       "<< insurancetype << endl;
    cout << setw(43) <<"Optional Extras:";
    //start of validation for extras
    if( gps == 'Y' && childseat == 'Y' )
        cout << setw(10) << "Y" << endl;
    else if( gps == 'Y' && childseat == 'N' )
        cout << setw(10) << "Y" << endl;
    else if( gps == 'N' && childseat == 'Y')
        cout << setw(10) << "Y" << endl;
    else
        cout << setw(10) << "N" << endl;
    if( gps == 'Y' && childseat == 'N' )
    {
        if( stoi(daysamount) <= 3)
        {
            extra=stoi(daysamount) * 5;
        }
        else
        {
            extra=15;
        }
        cout << setw(43) <<"Cost Of Extras :"<<"      "<< extra << endl << endl;
    }
    else if( gps == 'N' && childseat == 'Y' )
    {
        if( stoi(daysamount) <= 12 )
        {
            extra=stoi(daysamount) * 12;
        }
        else 
        {
            extra=149;
        }
        cout << setw(43) <<"Cost Of Extras :"<<"          "<< extra << endl << endl;
    }
    else if( gps == 'Y' && childseat == 'Y' )
    {
        if( stoi(daysamount) <= 3)
        {
            extra=stoi(daysamount) * 5;
        }
        else
        {
            extra=15;
        }
        if( stoi(daysamount) <= 12 )
        {
            extra=extra + stoi(daysamount) * 12;
        }
        else 
        {
            extra=extra + 149;
        }
        cout << setw(43) <<"Cost Of Extras :"<<"      "<< extra << endl << endl;
    }
    else
    {
        cout << endl << endl;
    }
    //end of extras validation
    cost=rentday*stoi(daysamount);
    cout <<"Cost Details:"<< setw(27) <<"Cost of Hire:"<<"      "<< cost << endl;
    cout << setw(46) <<"Cost of Insurance :";
    //validation for insurance type
    if( stoi(age) <= 24 && stoi(age) >= 18 )
    {
        if( insurancetype == "CDW" )
            costinsur=costinsur + (stoi(daysamount) * 4);
        else 
            costinsur=costinsur + (stoi(daysamount) * 11);
        if( stoi(daysamount) <= 10)
            costinsur=costinsur + stoi(daysamount) * 32;
        else 
            costinsur+=325;
    }
    else 
    {
        if( insurancetype == "CDW" )
            costinsur=costinsur + (stoi(daysamount) * 4);
        else 
            costinsur=costinsur + (stoi(daysamount) * 11);
    }
    if(stoi(addrivers) > 0)
        costinsur=costinsur + (stoi(addrivers) * 8) * stoi(daysamount);
    cout <<"      "<< costinsur << endl;
    cost=cost + costinsur + extra;
    grossrev=cost + grossrev;
    //displaying of voucher 
    cout << setw(37) <<"Discount :";
    if(stoi(daysamount) > 3)
    {
        discount=cost * 0.15;
    }   
    else 
        discount=0.0;
    totaldiscount=totaldiscount + discount;
    cout <<"          "<< setprecision(2) << fixed << discount << endl;
    cost=cost - discount;
    cout << setw(41) <<"Cost-Discount:"<<"            "<< setprecision(2) << fixed << cost << endl;
    netrev=(cost - discount) + netrev;
    cout << setw(31) <<"Tax:"<<"              "<< setprecision(2) << fixed << cost * 0.195 << endl;
    cout << setw(43) <<"Handling charge:"<< setw(14) <<"EUR 3"<<endl;
    cost=cost + (cost * 0.195);
    cout << setw(38) <<"Total Cost:"<<"           "<< setprecision(2) << fixed << cost + 3 << endl;
}
bool AmountDay(string daysamount)
{//function checking the string taken in is digit
    for(int i=0; i < daysamount.length(); i++)
    {
        if(!isdigit(daysamount[i]))
        {
            return false;
        }
        else if(daysamount[i]<1)
        {
            return false;
        }
        else
            return true;
    }
}
bool AddingDriver(string addrivers)
{//function to check that the add driver is a digit 
    for(int i=0; i < addrivers.length(); i++)
    {
        if(!isdigit(addrivers[i]))
        {
            return false;
        }
        else
            return true;
        while( !AddingDriver(addrivers) )
        {
            cout <<"How many additional drivers? :";
            cin >> addrivers;
            system("CLS");
        }
    }
}
void gotoxy(short x, short y) {
    //for positioning used in intro screen
COORD pos = {x, y};
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
void Intro()
{
    //displays intro screen on opening the program
    int i=0,j=60;
    while(i!=80&&j!=0)
    {
            gotoxy(j,0);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,1);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,2);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,3);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,4);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,5);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,6);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,7);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,8);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,9);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,10);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,11);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,12);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,13);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,14);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,15);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,16);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,17);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,18);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,19);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,20);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,21);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,22);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,23);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,24);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(i,25);
            cout <<"MAGNIFICENT CAR HIRE";
            gotoxy(j,26);
            cout <<"MAGNIFICENT CAR HIRE";
            system("CLS");
            i++, j--;
    }   
    gotoxy(30,10);
    cout <<"########################";
    gotoxy(30,11);
    cout <<"#                      #";
    gotoxy(30,12);
    cout <<"# MAGNIFICENT CAR HIRE #";
    gotoxy(30,13);
    cout <<"#                      #";
    gotoxy(30,14);
    cout <<"########################";
}

I know i can do it with out having it in a function but wanted to have it like it is. any suggestions would be great

Functions with a plethora of arguments are IMO a sign of bad design.
Your VoucherPrint seems a bit overloaded. As an example, why not put the printing of costumer details in a separate function?

When there are more than 3 or 4 parameters it's better to create a structure or class to hold them all so that the function itself has only one parameter. It's a lot easier to read and understand that way.

why in the voucher print function its not displaying cost near hire cost

You need to put some print statements inside that function to display the values of all those parameters. Or better yet, learn to use your compiler's debugger.

Note: function AmountDay() doesn't work right either. Regardless of whether daysamount[i] is a digit or not the function returns on the first iteration of the loop. Also, daysamount is a string array, not an int array, so the second test to see if the value of daysamount[i] < 1 is not a valid test because daysamount[i] is a character, not an integer.

Here's how that function should work

bool AmountDay(string daysamount)
{//function checking the string taken in is digit
    for (int i = 0; i < daysamount.length(); i++)
    {
        if (!isdigit(daysamount[i]) || daysamount[i] == '0')
        {
            return false;
        }
    }
    return true;
}

AddDriver() also has a problem -- The function needs to return a value before it exits at the bottom of the function.

Thanks for that ive fixed those issues i would use a struct or class but have been told im not aloud too... I can get it working fine if i take the start menu out of a function and just print so i am assuming its not holding the value for the cost per day. Ive tried using pass by reference but still doesnt work so i will leave it out of functions instead thanks for your help

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.