i need some help with these errors that i am getting on my program.....

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • qwert7465
    New Member
    • Jan 2010
    • 6

    i need some help with these errors that i am getting on my program.....

    any help would be appreciated. here is my code:


    Code:
    // Final Project
    
    #include <iostream.h>
    #include <iomanip.h>		
    
    void checkout();
    void start_or_startover();
    void receipt();
    
    float subtotal, tax, total;
    
    // Prices
    float laptopprice = 799.99;
    float mouseprice = 12.99;
    float keyboardprice = 29.99;
    float moniterprice = 399.99;
    float usbprice = 16.99;
    float hdmiprice = 24.99;
    float lazerprice = 6.99;
    float powerprice = 9.99;
    
    // Quantity
    int laptopnumber;
    int mousenumber;
    int keyboardnumber;
    int moniternumber;
    int usbnumber;
    int hdminumber;
    int lazernumber;
    int powernumber;
    
    // Main Function
    int main()
    {
    	do
    	{ start_or_startover(); }
    	while (choice == 10);
    
    	receipt();
    
    	return 0;
    }
    
    {
    	cout << "Ferger's Technology Store" << endl << endl;
    
    
    	do
    	{
    	cout << "(1) HP Pavilion Intel Core 2 Duo Laptop		$799.99" << endl;
    	cout << "(2) Razer Black Wired Lazer Mouse				$12.99" << endl;
    	cout << "(3) Razer Keyboard Wired						$29.99" << endl;
    	cout << "(4) HP LCD Flatscreen Moniter					$399.99" << endl;
    	cout << "(5) SATA USB 8GB Flash Drive					$16.99" << endl;
    	cout << "(6) HDMI Full 1080p 6ft Cable					$24.99" << endl;
    	cout << "(7) Lazer Pointer								$6.99" << endl;
    	cout << "(8) Power Cord									$9.99 << endl;
        cout << "endl;
    		cout << "(9) Total" << endl;
    	cout << "(10) Cancel Order" << endl;
    	cout << " Please enter the choice number of the electronics that you would like to buy." << endl << endl;
    	cin >> choice;
    	cout << endl;
    
    	if (choice == 9)
    	{
    		chechout();
    	}
    	if (choice == 1 || choice == 2 || choice == 3 || choice == 4 || choice == 5 || choice == 6 || choice == 7 || choice == 8)
    	{
    	cout << " How many would you like? ";
    	cin >> choice_amount;
    	cout << endl;
    
    	if (choice == 1)
    	{
    		laptopnumber = choice_amount;
    	}
    
    	if (choice == 2)
    	{
    		mousenumber = choice_amount;
    	}
    
    	if (choice == 3)
    	{
    		keyboardnumber = choice_amount;
    	}
    
    	if (choice == 4)
    	{
    		moniternumber = choice_amount;
    	}
    
    	if (choice == 5)
    	{
    		usbnumber = choice_amount;
    	}
    
    	if (choice == 6)
    	{
    		hdminumber = choice_amount;
    	}
    	if (choice == 7)
    	{
    		lazernumber = choice_amount;
    	}
    	if (choice == 8)
    	{
    		powernumber = choice_amount;
    	}
    	}
    
    	if (choice == 10)
    	{
    		laptopnumber = 0;
    		mousenumber = 0;
    		keyboardnumber = 0;
    		moniternumber = 0;
    		usbnumber = 0;
    		hdminumber = 0;
    		lazernumber = 0;
    		powernumber = 0;
    	}
    	}
    	while (choice != 9);
    	}
    
    {
    	subtotal = (laptopnumber * laptopprice) + (mousenumber * mouseprice) + (keyboardnumber * keyboardprice) + (	subtotal = (laptopnumber * laptopprice) + (mousenumber * mouseprice) + (keyboardnumber * keyboardprice) + (	subtotal = (laptopnumber * laptopprice) + (mousenumber * mouseprice) + (keyboardnumber * keyboardprice) + (moniternumber * moniterprice) + (usbnumber * usbprice) + (hdminumber * hdmiprice) + (lazernumber * lazerprice) + (powernumber * powerprice);
    
    	tax = subtotal * .0875;
    
    	total = subtotal + tax;
    }
    void receipt()
    {
    	cout << "Thank you for your buisness. Here is your recipt." << endl << endl;
    	cout.setf(ios::fixed);
    	cout << "Items\t\t  " << "Number of items purchased \t Price of each item \t Total price" << endl;
    	cout << "HP Pavilion Intel Core 2 Duo Laptop \t "<< laptopnumber << "\t\t\t" << "$" << setprecision(2) << laptopprice << "\t\t   " << "$" << (laptopnumber * laptopprice) << endl;
    	cout << "Razer Black Wired Lazer Mouse \t "<< mousenumber << "\t\t\t" << "$" <<  mouseprice << "\t\t   " << "$" << (mousenumber * mouseprice) << endl;
    	cout << "Razer Keyboard Wired \t "<< keyboardnumber << "\t\t\t" << "$" << keyboardprice << "\t\t   " << "$" << (keyboardnumber * keyboardprice) << endl;
    	cout << "SATA USB 8GB Flash Drive \t "<< usbnumber << "\t\t\t" << "$" << usbprice << "\t\t   " << "$" << (usbnumber * usbprice) << endl;
    	cout << "HDMI Full 1080p 6ft Cable \t "<< hdminumber << "\t\t\t" << "$" << hdmiprice << "\t\t   " << "$" << (hdminumber * hdmiprice) << endl;
    	cout << "Lazer Pointer \t "<< lazernumber << "\t\t\t" << "$" << lazerprice << "\t\t   " << "$" << (lazernumber * lazerprice) << endl;
    	cout << "Power Cord \t "<< powernumber << "\t\t\t" << "$" << powerprice << "\t\t   " << "$" << (powernumber * powerprice) << endl;
    
    	cout << "\t\t Subtotal \t $" << subtotal << endl;
    	cout << "\t\t Tax \t\t $" << tax << endl;
    	cout << "\t\t Total \t\t $" << total << endl << endl << endl;
    }
    and here is the errors that i am getting:

    --------------------Configuration: finalproject - Win32 Debug--------------------
    Compiling...
    finalproject.cp p
    H:\finalproject .cpp(14) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(15) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(16) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(17) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(18) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(19) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(20) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(21) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    H:\finalproject .cpp(38) : error C2065: 'choice' : undeclared identifier
    H:\finalproject .cpp(45) : error C2447: missing function header (old-style formal list?)
    H:\finalproject .cpp(58) : error C2001: newline in constant
    H:\finalproject .cpp(59) : error C2001: newline in constant
    H:\finalproject .cpp(130) : error C2447: missing function header (old-style formal list?)
    Error executing cl.exe.

    finalproject.ob j - 5 error(s), 8 warning(s)
  • weaknessforcats
    Recognized Expert Expert
    • Mar 2007
    • 9214

    #2
    Code:
    H:\finalproject.cpp(14) : warning C4305: 'initializing' : truncation from 'const double' to 'float'
    This means that symbolic constants (like 12.99) are doubles but your variable is a float. You are being warned that the value in the double may lose accuracy when converted to a float. Recommendation: Never use float. Stick with double unless you can bwrite down on paper the technical reason why it has to be a float.

    H:\finalproject .cpp(38) : error C2065: 'choice' : undeclared identifier
    Here you refer to a variable (choice) that you have never defined.

    H:\finalproject .cpp(45) : error C2447: missing function header (old-style formal list?)
    Your braces are out of balance. Be sure you have matching {} pairs.

    H:\finalproject .cpp(58) : error C2001: newline in constant
    Here a constant is missing a ".

    H:\finalproject .cpp(130) : error C2447: missing function header (old-style formal list?)
    Again your braces are out of balance.

    Te exact line number where the compiler got into trouble is in the error.

    Comment

    • qwert7465
      New Member
      • Jan 2010
      • 6

      #3
      sorry to ask another question, but to be specific, what should i do exactly? im not really good with this programming thing and i would greatly appreciate specifically what to do :)

      Comment

      • weaknessforcats
        Recognized Expert Expert
        • Mar 2007
        • 9214

        #4
        Change your float variables to double.

        Verify every one of you { has a matching }. Remember, this error can make a function look like it is written inside another function:

        Code:
        void Function1()
        {
        <-------------missing }
        void Function2()
        {
        
        }
        Make sure every " has a matching " on the same line:

        Code:
        cout << "hello
                    world!";
        should be:
        Code:
        cout << "Hello"
                    " world";
        or
        Code:
        cout << "Hello world";
        In any case, the procedure is to fix the first error/warning and then rebuild. Then fix the first error again. Often later errrors are the result of previous errors.

        Comment

        • qwert7465
          New Member
          • Jan 2010
          • 6

          #5
          i did what you said about the " and the matching " but the part with { and the matching }, i cant find where to put the other one. when i put in another one after my int main() i get a ton of errors requiring ;.

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            You have to go thriugh the code carefully and make sure your {} are paired up correctly.

            Here's the first problem:

            Code:
            int main() 
            { 
                do 
                { start_or_startover(); } 
                while (choice == 10); 
              
                receipt(); 
              
                return 0; 
            }     <<<<<<<<< end of main()
              
            {     <<<<<<<<<<<<what's this for?
                cout << "Ferger's Technology Store" << endl << endl;

            Comment

            Working...