Heres my code:

#include <cstdlib>
#include <iostream>



using namespace std;

//Function prototypes
char   GetTaxCode(void);
int    GetProductId(void);
int    GetQuantity(void);
float  GetProductPrice(void);
char   InvoiceInitilization(void);


int main(int argc, char *argv[])
{
//Variable declarations
    float gSt = .01;
    float pSt = .02;
    int productId;
    int quantity; 
    char taxCode;
    float taxAmt;
    float productPrice;
	int shippingFee = 10;
    char invoiceInitilization;
	char startInvoice;
	float total;
	char exitOnInput;
    
	startInvoice = InvoiceInitilization();
	
//If user entered n or N exit
	while ( startInvoice != 'n' || startInvoice != 'N' )
	{
	productId = GetProductId();
	quantity = GetQuantity();
	productPrice = GetProductPrice();
	taxCode = GetTaxCode();
			
			
			
//Adding taxes to cost
	if ( taxCode =='P' )
		{
			taxAmt = productPrice*pSt*quantity;
		}

	else

		if ( taxCode == 'G' )
			{
				taxAmt = productPrice*gSt*quantity;
			}

		else 

			if ( taxCode == 'B' )
				{
					taxAmt = productPrice*gSt*quantity + productPrice*pSt*quantity;
				}
		else
	
			if ( taxCode == 'E' )
				{
	
					taxAmt = 0;
        	  }
			

	
	total = productPrice + taxAmt + shippingFee;

	cout << "Product :                          " <<productId     <<endl;
	cout << "Quantity:			    		    " <<quantity      <<endl;
	cout << "Cost    :			    			" <<productPrice  <<endl;
	cout << "Taxes   :			    			" <<taxAmt <<endl;
	cout << "Shipping:			    			" <<shippingFee   <<endl;
	cout <<  endl;
	cout << "Total   :			    			" <<total         <<endl;
	
}
    cout <<"Enter any letter followed by 'Enter' to exit"<<endl;
    cin >> exitOnInput;
    return 0;
}

//If user enters Y program starts
char InvoiceInitilization(void)
	{
        char invoiceInitilization;
		cout << "Do you want to enter an invoice? Y(Yes) or N(No)"<<endl;
		cin >>   invoiceInitilization;
		
		while ( invoiceInitilization != 'y' || invoiceInitilization != 'Y'
			   || invoiceInitilization != 'n' || invoiceInitilization != 'N' )
		{
			cout << "You must enter Y or N. You entered "<< invoiceInitilization <<endl;
			cout << "Do you want to enter an invoice? Y(Yes) or N(No)"<<endl;
			cin >> invoiceInitilization;
		}
		
		return invoiceInitilization;
	}

//Getting the product ID number
int GetProductId(void)
	{
        int productId;
		
		cout << "Enter the product ID number" << endl << endl;
		cin >> productId;
		
		while ( productId <1000 || productId >9999 )
		{
			cout <<"Product ID's must range from 1000-9999"<< endl;
			cout <<"You entered "<<productId<<" please re-enter ID"<<endl;
			cin >> productId;
		}

		return productId;
}

//Getting quantity of products to be processed
int GetQuantity(void)
	{
        int productQuantity;
		cout << "Enter the quantity" <<endl <<endl;
		cin >> productQuantity;
		
//Cant have more than 99 products or < 1
		while ( productQuantity < 1 || productQuantity > 99 )
		{
			if ( productQuantity < 1 )
			{
				cout <<"A minimum quantity of 1 is required, you entered"<<productQuantity<<endl;
				cout <<"Re-enter the quantity"<<endl;
				cin >> productQuantity;
				cout << endl;
			}
			
			else
				if ( productQuantity > 99 )
			{
				cout <<"Up to 99 items are permitted, you entered "<<productQuantity<<endl;
				cout <<"Re-enter the quantity"<<endl;
				cin >> productQuantity;
				cout << endl;
			}
		}
		
		return productQuantity;
}

//getting the price of product
float GetProductPrice(void)

	{
        float productPrice ;              
		cout << "Enter the price of the product" << endl << endl;
		cin >> productPrice;

//products cant cost <0 or >1000
		while ( productPrice <=0  || productPrice > 1000 )
		{
			if ( productPrice <= 0 )
			{
				cout << "All products must be greater than $0.00, you entered ";
				cout << productPrice << endl;
				cout << "Re-enter the price"<<endl;
				cin >> productPrice;
				cout <<endl;
			}
			else
				if ( productPrice > 1000 )
			{
				cout << "All products must be less than $1000.00, you entered ";
				cout << productPrice << endl;
				cout << "Re-enter the price"<<endl;
				cin >> productPrice;
				cout <<endl;
			}
		}
		return productPrice;
		
}

//Getting tax code of the product (gst pst etc...)
char GetTaxCode(void)
{
        
        char taxCode;
		cout << "Enter the tax code P(pst) G(gst) B(pst and gst)" << endl;
		cout << "or E(Tax exempt) (Upper Case Only)" << endl << endl;
		cin >> taxCode;
	
	while ( taxCode != 'P' || taxCode != 'G' || taxCode != 'B' || taxCode != 'E' )
	{
		cout <<"Only P G B E are valid tax codes. You entered "<< taxCode <<endl;
		cout <<"Note: Codes must be capitalized. Re-enter the tax code" << endl;
		cin >> taxCode;
	}
     
        return taxCode;
}

When I run the program it keeps displaying:

"You must enter Y or N. You entered y
Do you want to enter an invoice?"

But when I enter y or Y I want it to exit the loop and continue with the rest of the program....
Can someone plz tell me what I'm doing wrong? This is driving me nuts.
Thx in advance.

This is the important part:

//If user enters Y program starts
char InvoiceInitilization(void)
	{
        char invoiceInitilization;
		cout << "Do you want to enter an invoice? Y(Yes) or N(No)"<<endl;
		cin >>   invoiceInitilization;
		
		while ( invoiceInitilization != 'y' || invoiceInitilization != 'Y'
			   || invoiceInitilization != 'n' || invoiceInitilization != 'N' )
		{
			cout << "You must enter Y or N. You entered "<< invoiceInitilization <<endl;
			cout << "Do you want to enter an invoice? Y(Yes) or N(No)"<<endl;
			cin >> invoiceInitilization;
		}
		
		return invoiceInitilization;
	}

For some reason it wont exit no matter what I enter.

while ( invoiceInitilization != 'y' || invoiceInitilization != 'Y'
			   || invoiceInitilization != 'n' || invoiceInitilization != 'N' )

Those should be && operators, not ||.
You can simplify that by converting to either upper or lower case so that you don't have to test for all 4

while( toupper(invoiceInitialization) != 'Y' && toupper(invoiceInitialization) != 'N')

Wow I think I've been in front of the computer screen way to long... Thanks a lot Ancient dragon you're my new hero :)

This article has been dead for over six months. Start a new discussion instead.