Hi there pleasse help. I get the warning C4700: uninitialized local variable 'BottlesLeft' used. Here is what the CalcNrCases is supposed to do: A value-returning function called CalcNrCases( BottleType, NrBottles, BottlesLeft ) that will calculate and return the number of full cases (NrCases) as an integer. It will also calculate and pass back how many bottles are left that will not be paid for (BottlesLeft) as an integer. The type of the bottle determines how many fit into a case:
• ‘S’ or ‘s’ = 375ml bottles, 10 per case
• ‘M’ or ‘m’ = 500ml bottles, 8 per case
• ‘L’ or ‘l’ = 750ml bottles, 6 per case
Also I am not sure if my formulas are correct.

#include <iostream>
#include <string>

using namespace std;


//Function Prototypes

string GetName();
void GetInput(char&, int&);
int CalcNrCases(char, int, int);

	





void main ()
{
	 string CustName;
	 char BottleType;
	 int NrBottles;
	 int BottlesLeft;
	 int NrCases;

     CustName = GetName();
	 while (CustName != "X" && CustName != "x")
	{
	

		GetInput(BottleType, NrBottles);
		
		NrCases = CalcNrCases(BottleType, NrBottles, BottlesLeft);
	    	
	 }

	


}





//Function Definitions


string GetName()

//This function prompts for a name and return a custormer's name
{

	string CustName;

	cout << "Enter the customer name: ";
	cin >> CustName; 

	

	return CustName;


}


void GetInput(char& BottleType, int& NrBottles)
	//This function prompts for a bottle type and the number of bottles
{
	cout << "Enter the bottle type: ";
	cin >> BottleType;

	//VALIDATION
	while (BottleType != 's' && BottleType != 'S' && BottleType != 'm' && BottleType != 'M' && BottleType != 'l' && BottleType != 'L')
	{
		cout << " Incorrect bottle type, please enter a s, S, m M or l L " << endl;
		cin >> BottleType;
	}

	cout << "Enter the number of bottles returned: ";
	cin >> NrBottles;

	//validation

	while (NrBottles <= 0)
	{
		cout << "The number of bottles you have entered is invalid, please re-enter a valid number larger than zero: ";
		cin >> NrBottles;
	 }

}

int CalcNrCases(char BottleType, int NrBottles, int BottlesLeft)
{
	
	int NrCases;
	BottlesLeft = 0;
	
	
	
	if (BottleType == 's' && BottleType == 'S')
         NrCases = 10;
	else
		if (BottleType == 'm' && BottleType == 'M')
			NrCases = 8;
		else
			NrCases = 6;
	while (NrBottles != 10 && NrBottles != 8 && NrBottles != 6)
	{
		BottlesLeft = NrCases - NrBottles;

	}
	
return NrCases;

}

Edited 5 Years Ago by Nick Evan: Removed [tex] tags

Initialize all variables which you have used, before actually using them in code.
It will help you in getting rid of the warning.

Your CalcNrCases() function should take the BottlesLeft parameter by reference if you intend to modify its value as an additional output of your function. As so:

//the prototype:
int CalcNrCases(char, int, int&);

//...

//the function:
int CalcNrCases(char BottleType, int NrBottles, int& BottlesLeft) 
{
This article has been dead for over six months. Start a new discussion instead.