warning C4305: 'return' : truncation from 'const int' to 'bool' & error C2059: syntax error : '}'

Hi,
I have 1 error and 1 warning when I compile my code. Can anyone help?
Thanks
Kaz
KazITAsked:
Who is Participating?
 
leflonConnect With a Mentor Commented:
and what about the return value of AskForStart()? the prog will continue no matter if you enter 'yes' or 'no'.
give the return values a chance :).

leflon
0
 
AlexFMCommented:
Please show your code.
0
 
leflonCommented:
hi KazIT,

the variable you return from a function seems to be different from the return type in function declaration.
function returns a const int but the declaration says the return type is bool&.
but i agree with AlexFm, some code would be nice.

leflon
0
Cloud Class® Course: Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

 
stefan73Commented:
Hi KazIT,
Looks like you tried to return an int as bool - if you have something like
return my_int
use
return (my_int != 0);
instead.

There is not much use in returning a bool reference anyway.

Or you have a problem with {} nesting.

Cheers,
Stefan
0
 
KazITAuthor Commented:
The entire code isn't finished this is just the part I am up to
I have a set order that the program has to appear in
first the "Welcome function that has to be hard coded"
then "are there any customers Y or N"
while yes continue
then "Please enter your Customer ID"
the customer Id has limits 0000 to 9999
which is the part I am having problems with.
I will post the entire code though

//PREPORCESSOR DIRECTIVES
#include <iostream>         //FOR CIN AND COUT
#include <iomanip>          //SETW
#include <cctype>           //FOR TOUPPER
#include <string>           //FOR STRING CLASS

using namespace std;        //REQUIRED WHEN USING IOSTREAM

//FUNCTION PROTOTYPES
void Welcome (void);
bool AskForStart();
bool AskForCustomerID(int & customerId);
int GetIntegerResponse(int Lower=1000, int Upper=9999);

void DisplayStock (int AxleStock, int BearingsStock, int BrakeStock);
void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                        int AxleStock, int BearingsStock, int BrakeStock);
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int&
                           BrakeStock,int AxleQty,int BearingsQty,
                                       int BrakeQty);
float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty);
void DisplayInvoice ( int CustomerId, int AxleQty, int BearingsQty,
                      int BrakeQty);
void Reorder (int AxleStock, int BearingsStock, int BrakeStock);

//MAIN FUNCTION
void main()
{
//DEFINE VARIABLES
int AxleStock =0;                  //AXLES IN STOCK
int BearingsStock =0;            //BEARINGS IN STOCK
int BrakeStock =0;          //BRAKES IN STOCK
int CustomerId =0;
int AxleQty =0;
int BearingsQty =0;
int BrakeQty =0;
int Integer =0;              
int QuantityOnHand =0;     //QUANTITY ON HAND (GLOBAL)
int reorderLevel =0;     //REORDER LEVEL
int Lower = 1000;
int Upper = 9999;
float TotalCostOfParts =0.0;     //TOTAL COSTS OF PARTS (GLOBAL)
float Price = 0.0;          //PRICE OF ITEM (GLOBAL)
string Part = " ";          //PART (GLOBAL)

//CALL FUNCTIONS
Welcome ();
AskForStart();
GetIntegerResponse(Lower,Upper);
DisplayStock (AxleStock,BearingsStock,BrakeStock);
GetOrderQuantities(AxleQty,BearingsQty,BrakeQty,AxleStock,BearingsStock,
                           BrakeStock);
UpdatePartsStock(AxleStock,BearingsStock,BrakeStock,AxleQty,BearingsQty,
                         BrakeQty);
TotalCostParts(AxleQty,BearingsQty,BrakeQty);
DisplayInvoice (CustomerId,AxleQty,BearingsQty,BrakeQty);
Reorder (AxleStock,BearingsStock,BrakeStock);
}
//END main()
//-----------------------------------------------------------------------
//THIS FUNCTION DISPLAYS A WELCOME MESSAGE THAT INCLUDES
//YOUR  NUMBER AND NAME
void Welcome (void)
{
string welcomeMessage ="Welcome to S0023838 Karen Stedman Spare Parts.";
string supplying = "We supply parts for your vehicle. ";

 cout << welcomeMessage <<endl
       << supplying <<endl<<endl;}
//-----------------------------------------------------------------------
//THIS OUTPUT ASKS IF THERE ARE ANY CUSTOMERS AND CHECKS FOR INCORRECT INPUT.
bool AskForStart()
{
      char Reply = ' ';
      cout << "Are there any customers? (Y/N) => ";
      cin >> Reply;               //READ USER RESPONSE
      Reply = toupper(Reply);     //CONVERT TO UPPERCASE
      
      // IF WE DON'T HAVE A YES OR NO KEEP PROMPTING UNTIL WE DO
      while ((Reply != 'N') && (Reply != 'Y'));
      {
            cout << "ERROR:  Valid responses are 'Y' or 'N'" <<endl
                  << "Are there any customers? (Y/N) => ";
            cin >> Reply;
            Reply = toupper (Reply);
      }//END while
      return (Reply == 'Y');
}

bool AskForCustomerID(int & customerId) (THIS PART IS WHERE THE PROBLEM IS)
{
      cout << "Please enter your Customer ID  (or -1 to quit)=>";
      cin >> customerId;
      
                   return (customerId != -1);
                  
                   int CustomerId =0;
                  
                   if (!AskForStart())
                         return 1;
                   if (!AskForCustomerID(CustomerId))
                         return 2;
}
int GetIntegerResponse(int Lower,int Upper)
{
      int Response=0;
      do
      {
            int ReadInteger(Response);
            if (Response < Lower || Response > Upper)
            {
                  cerr<<"\n\t\tERROR: Number must be between "
                        << Lower << "and" << Upper << "=>";
            }while (Response < Lower || Response > Upper);
            
            return Response;
      }
}
//----------------------------------------------------------------------
//DEFINE AND INITIALISE PART 1 OBJECTS AND VARIABLES
int Code1 = 1;                              //CODE PART 1
string Part1 = "Axle";               //PART REAR AXLE
float Price1 = 128.00;                    //PRICE PART 1
int QuantityOnHand1 = 5;               //QUANTITY ON HAND PART 1
int reorderLevel1 = 2;                    //REORDER LEVEL PART 1

//DEFINE AND INITIALISE PART 2 OBJECTS AND VARIABLES
int Code2 = 2;                              //CODE PART 2
string Part2 = "Bearings";               //PART BEARINGS
float Price2 = 25.50;                    //PRICE PART 2
int QuantityOnHand2 = 20;               //QUANTITY ON HAND PART 2
int reorderLevel2 = 10;                    //REORDER LEVEL PART 2

//DEFINE AND INITIALISE PART 3 OBJECTS AND VARIABLES
int Code3 = 3;                              //CODE PART 3
string Part3 = "Brake Pads";          //PART BRAKE PADS
float Price3 = 30.00;                    //PRICE PART 3
int QuantityOnHand3 = 12;               //QUANTITY ON HAND PART 3
int reorderLevel3 = 6;                    //REORDER LEVEL PART 3

//THIS FUNCTION DISPLAYS A LIST OF THE ITEMS AVAILABLE, THEIR PRICES
//AND THE NUMBERS OF EACH ITEM THAT ARE AVAILABLE FOR SALE
void DisplayStock (int AxleStock, int BearingsStock, int BrakeStock)
{
      cout << "\nOur current stock is: " <<endl;

//DISPLAY HEADINGS

cout  << setw(4) <<"Code"
      << setw(8) <<"Part"
      << setw(24)<<"Quantity On Hand"
      << setw(8) <<"Price" << endl;

//DISPLAY CURRENT STOCK
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);

cout  << setw(2) << Code1
      << setw(10) << Part1
      << setw(16) << QuantityOnHand1
      << setw(13) << "$ " << Price1 << endl;

cout  << setw(2) << Code2
      << setw(14) << Part2
      << setw(13) << QuantityOnHand2
      << setw(13) << "$  " << Price2 << endl;

cout  << setw(2) << Code3
      << setw(16) << Part3
      << setw(11) << QuantityOnHand3
      << setw(13) << "$  " << Price3 << endl;
}//END Display Stock
//---------------------------------------------------------------------
    //THIS FUNCTION OBTAINS FROM THE USER THE ITEM CODE AND
    //THE QUANTITY OF EACH ITEM THAT ARE REQUIRED BY THE USER

void GetOrderQuantities(int& AxleQty, int& BearingsQty, int& BrakeQty,
                        int AxleStock, int BearingsStock, int BrakeStock)
                                    
{
      int Code ;      //ITEM CODE                  
      cout << "Enter the code for the part you want to buy =>" ;
      cin >> Code;
      int Integer;                               
      cout << "How many of this part would you like => ";
      cin >> Integer;    

}
//----------------------------------------------------------------------
//THIS FUNCTION DISPLAYS THE INVOICE DETAILS
void DisplayInvoice ( int CustomerId, int AxleQty, int BearingsQty,
                               int BrakeQty)
{
         string Part = " ";
         int Quantity = 0;
         float Cost = 0.0;

    cout << "Invoice for Customer Number:" << CustomerId << endl;

    cout << "Part\tQuantity\tCost" <<endl;

    cout << setw(2) << Part
             << setw(10)<< Quantity
             << setw(16)<< Cost<<endl<<endl;
}
//THIS FUNCTION CALCULATES AND RETURNS THE TOTAL COST OF THE ITEMS
//THAT HAVE BEEN ORDERED

float TotalCostParts(int AxleQty, int BearingsQty, int BrakeQty)
{

    cout << "Total Cost of parts: $" << TotalCostParts <<endl;
return 0;
}//END Display Invoice
//--------------------------------------------------------------------
//THIS FUNCTION UPDATES THE QUANTITY OF EACH ELEMENT THAT REMAINS IN STOCK
//AFTER THE CUSTOMER IS SERVED
void UpdatePartsStock(int& AxleStock, int& BearingsStock, int&
                           BrakeStock,
                           int AxleQty, int BearingsQty, int BrakeQty)
{
      int Integer =0;
      int Code =0;
 switch (Code)
     {
     case 1:     AxleQty = AxleStock - Integer;
          break;

     case 2:     BearingsQty = BearingsStock - Integer;
          break;

     case 3:     BrakeQty = BrakeStock - Integer;
          break;
         
     case 4:     cout << "\nInvalid Code......Try again.";
     }//END switch
}
//--------------------------------------------------------------------
//THIS FUNCTION DETERMINES WHICH ITEMS SHOULD BE REORDERED
void Reorder (int AxlesStock, int BearingsStock, int BrakeStock)
{
      int reorderLevel =0;
   if (AxlesStock < reorderLevel)
      {
        cout << "The following parts should be reordered: " <<endl
                   << "Axles" <<endl;
    }
      if (BearingsStock < reorderLevel)
      {
          cout << "The following parts should be reordered: " <<endl
                   << "Bearings" <<endl;
      }
      if (BrakeStock < reorderLevel)
      {
            cout << "The following parts should be reordered: " <<endl
                   << "Brakes" <<endl;
      }
      else
    {
        cout << "No parts to be reordered at present. " << endl;
      }  
   
}

THANKS
0
 
Karl Heinz KremerCommented:
You are very likely mixing BOOL and bool: I've seen this (a lot) when a windows function returns a BOOL, but you've defined a bool and assign the return code to your bool variable. If you want to get rid of this warning, do something like this (as already suggested by Stefan):

bool myBool = (WinAPIFunctionReturningBool() != 0);

In addition to this you have a missing '}'. This error is unrelated.
0
 
Karl Heinz KremerConnect With a Mentor Commented:
You are returning a bool, but your return values are "1" and "2". This is wrong. Use false and true instead.
0
 
Karl Heinz KremerCommented:
Your function declarations don't have the correct return types.
0
 
Karl Heinz KremerCommented:
Sorry, I wanted to say "main()" does not have the correct return type: THe standard requires that main() returns int.
0
 
jkrConnect With a Mentor Commented:
khkremer is right about that. furthermore, 'GetIntegerResponse()' should be

int GetIntegerResponse(int Lower,int Upper)
{
    int Response=0;
    do
    {
         int ReadInteger(Response);
         if (Response < Lower || Response > Upper)
         {
              cerr<<"\n\t\tERROR: Number must be between "
                   << Lower << "and" << Upper << "=>";
         } // <---! closing bracket here
    }while (Response < Lower || Response > Upper);
         
         return Response;
}
0
 
KazITAuthor Commented:
thankyou  khkremer that solved my bool prob.

jkr...placing that closing bracket where you advised allows me to compile and build without errors, however when I run the program and answer Yes or No to "are there any customers" it hangs repeating over and over" Error number must be between 1000 and 9999. " but that shouldn't come up until I ask for the customer ID.  

Kaz
0
 
jkrCommented:
>>but that shouldn't come up until I ask for the customer ID.  

You might want to implement 'ReadInteger()' then. There is no such function in the above code, thus the runtime problem.
0
 
KazITAuthor Commented:
jkr,
do you mean this after the GetIntegerResponse function?
void ReadInteger(int &Integer)
{
      cin >> Integer;
      while (cin.fail())
      {
            cin.clear();
            Clear();
            cout << "ERROR: You must enter an integer => ";
            cin >> Integer;
      }
      Clear();
}
void Clear(void)
{
      char Char=' ';
      while (Char!='\n')
      {
            cin.get(Char);
      }
}
I'm not sure if this is what you meant.
However, I still get the same run problem with these added 2 functions so I'm obviously wrong again somewhere.

Kaz
0
 
jkrCommented:
>>do you mean this after the GetIntegerResponse function?

Yes, this was not part of the code you posted. Now, it should read

void Clear(void)
{
    char Char=' ';
    while (Char!='\n')
    {
         cin.get(Char);
    }
}
void ReadInteger(int &Integer)
{
    cin >> Integer;
    while (cin.fail())
    {
         cin.clear();
         Clear();
         cout << "ERROR: You must enter an integer => ";
         cin >> Integer;
    }
    Clear();
}
int GetIntegerResponse(int Lower,int Upper)
{
    int Response=0;
    do
    {
         ReadInteger(Response);
         if (Response < Lower || Response > Upper)
         {
              cerr<<"\n\t\tERROR: Number must be between "
                   << Lower << "and" << Upper << "=>";
         }
    }while (Response < Lower || Response > Upper);
         
         return Response;
}

(right in this order)
0
 
KazITAuthor Commented:
This is a printout of my screen after the run command
Welcome to S0023838 Karen Stedman Spare Parts.
We supply parts for your vehicle.

Are there any customers? (Y/N) => y
ERROR:  Valid responses are 'Y' or 'N' //! gives this response whether Y or N is put in the first time.
Are there any customers? (Y/N) => Y
//!! Nothing happens after this unless I enter a couple of times and key something

1234


2
2

Our current stock is:                                     )//!! this is what is supposed to happen
Code    Part        Quantity On Hand   Price      )after Yes to "are there any customers"
 1      Axle               5           $ 128.00           )
 2      Bearings           20          $  25.50         )
 3      Brake Pads         12          $  30.00        )
Enter the code for the part you want to buy =>1
How many of this part would you like => 2
Total Cost of parts: $00401357 //! I'm still working on this from here down.
Invoice for Customer Number:0
Part    Quantity        Cost
           0            0.00

No parts to be reordered at present.

Kaz
0
 
jkrCommented:
It seems to me that you should find out what you want your program to do first...
0
 
Karl Heinz KremerConnect With a Mentor Commented:
Actaully, it's not so much "what you want your program to do first", it's "what you want your program to do next" :-) This is from your main() function:

//CALL FUNCTIONS
Welcome ();
AskForStart();
GetIntegerResponse(Lower,Upper);
DisplayStock (AxleStock,BearingsStock,BrakeStock);

You are missing one call between AskForStart() and GetIntegerResponse().
0
 
KazITAuthor Commented:
Thanks everyone for the assistance

KazIT
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.