CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Oct 2005
    Posts
    3

    Angry Errors in my program

    Hi, I am trying to write my C++ program for my OOP class and my program keeps giving me multiple errors and I am getting really frustrated. My code is pasted below. Can someone please help and give me the corrections? By the way this is the beginning of the class so we have not learned everything yet. This program is based on before even knowing anything about classes, structures, etc.

    code(formatting is messed up since I copied and pasted):
    Code:
    #include <iostream>
    using namespace std;
    
    //Collects data for adding/dropping item
    void getData(double& regularPrice, double& VIPPrice, double& qty);
    
    //This function adds/drops items
    double addDrop(regularPrice, VIPPrice, qty, double& totalAmt, double& totalSavings);
    
    //This function makes a payment
    double payment(double& dailyTotal, totalAmt, totalSavings, double& VIP);
    
    //This function dispenses change
    double totalChange(double& due, double& paid, double& change);
    
    int main()
    {
    	
    	//variable declarations
    	int employeeCode, regularPrice, VIPPrice, qty, change_in_cents, dollars, quarters,
    		dimes, nickels, pennies;
    	char quit, function;
    	double totalAmt, totalSavings, VIP, dailyTotal, due, paid, change;
    
    	cout<< "Welcome to the POS System of Min's Food!\n";
    	cout<< "Enter your employee code:";
    	cin>> employeeCode;
    
    	cout.setf(ios::fixed);
    	cout.setf(ios::showpoint);
    	cout.precision(2);
    
    	dailyTotal = 0;
    	VIP = false, totalAmt = 0, totalSaving = 0;
    	//repeatedly process transactions
    	do
    	{
    		cout<< "Function:";
    		cin>> function;
    		switch(function){
    			case 'a':
    			case 'A':
    				getData(regularPrice, VIPPrice, qty);
    				addDrop(regularPrice, VIPPrice, qty, totalAmt, totalSavings);
    			break;
    			case 'd':
    			case 'D':
    				getData(regularPrice, VIPPrice, qty);
    				addDrop(regularPrice, VIPPrice, qty, totalAmt, totalSavings);
    			break;
    			case 'v':
    			case 'V':
    				VIP = true;
    			break;
    			case 'p':
    			case 'P':
    				payment(dailyTotal, totalAmt, totalSavings, VIP);
    			break;
    			default:
    				cout<< "Please enter correct function(A,D,V,P)!/n";
    	}
    		do
    		{
    			cout<< "Do you want to quit the program(Y/N)?:";
    			cin>> quit;
    			quit = toupper(quit);
    		}while (quit != 'Y' && quit != 'N');
    	}while (quit != 'Y');
    	cout<< "Cashier:" << employeeCode << "Your total sales today are $"
    		<< dailyTotal << endl;
    	cout << "Thank you for using the program. Good Bye!";
    	return(0);
    }
    void getData(regularPrice, VIPPrice, qty)
    { 
    	cout<< "Regular Price:";
    	cin>> regularPrice;
    	while(regularPrice < 0)
    	{	
    		cout << "VIPPrice:";
    	    cin>> VIPPrice;
    		if(regularPrice < 0)
    			cout << "Please enter a non-negative number";
    		cout << "Regular Price:";
           }
          while(VIPPrice < 0)
    	  {
    		  cout << "Quantity:";
    		  if (VIPPrice < 0)
    			  cout << "VIP Price shouldn't be higher than regular price!";
    	  }
    }
    double addDrop(regularPrice, VIPPrice, qty, totalAmt, totalSavings);
    {
    	totalAmt = totalAmt + qty * Price;
    	totalSavings = totalSavings + (regularPrice - VIPPrice)* qty;
    	return 0;
    }
    double payment(dailyTotal, totalAmt, totalSavings, VIP);
    {
    	if(VIP=true)
    		due = totalAmt - totalSavings;
    	else
    	due = totalAmt;
    
    	dailyTotal = dailyTotal + due
    		cout << "Amount Due:";
    	cin >> due;
    	cout << "Amount Paid:";
    	cin >> paid;
    	while(paid < due)
    	{ 
    		change = paid-due;
    		change_in_cents = static_cast<int>(change * 100 + 0.5);
    		//+ 0.5 because of precision problems.
    		dollars = change_in_cents/100;
    		change_in_cents -= dollars * 100;
    		quarters = change_in_cents/25;
    		change_in_cents -= quaters * 25;
    		dimes = change_in_cents/10;
    		change_in_cents -= dimes * 10;
    		nickels = change_in_cents/5;
    		change_in_cents -= nickels * 5;
    		pennies = change_in_cents;
    		cout << "Your change:" << dollars << "dollars"
    			<< quarters << "quarters"
    			<< dimes << "dimes"
    			<< nickels << "nickels"
    			<< pennies << "pennies." << endl;
    Last edited by Ejaz; October 12th, 2005 at 11:59 PM. Reason: Code tag added

  2. #2
    Join Date
    May 2005
    Location
    United States
    Posts
    526

    Re: Errors in my program

    Most of your syntax errors should be obvious from the error messages given when you try to compile your code. For example, here:
    Code:
    double addDrop(regularPrice, VIPPrice, qty, double& totalAmt, double& totalSavings);
    Every variable in a function prototype like this must have its type specified, and yet you have not specified the type of regularPrice, VIPPrice, or qty. You make the same error in many places throughout your program. You also have a few places where you're attempting to use variables without having declared them first. You have cases where you're attempting to call a function with the incorrect number of parameters, or are trying to pass the wrong type of parameters. I think you probably just need to read up on basic syntax a little more closely. An example program:
    Code:
    // Function prototype - lays out the function name, return type, and parameter list.
    // Ends with a semicolon. Variable types are required; names are optional.
    int f(int a, int b);
    
    // In other words, writing this:
    //
    //     int f(int, int);
    //
    // would be an acceptable alternative, but writing this:
    //
    //     int f(a, b);
    //
    // is wrong, because the compiler doesn't know what a and b are supposed to be.
    
    int main()
    {
        int num1 = 1;
        int num2 = 2;
    
        // When calling a function you must use the correct number and types of parameters.
        f(num1, num2);
    
        return 0;
    }
    
    // Function implementation. No semicolon following the header.
    int f(int a, int b)
    {
        // Must return a value of the correct type.
        return a + b;
    }
    Also, you didn't post your entire code. It cuts off abruptly at the end. Finally, for future reference, when posting code please enclose it in the [code]...[/code] tags. This will preserve formatting as in the example above.

  3. #3
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Errors in my program

    In the future, also post the exact error messages you get, this helps us pinpointing the problem.
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  4. #4
    Join Date
    Jun 2005
    Location
    Chennai , India
    Posts
    1,375

    Thumbs up Re: Errors in my program

    Look at this link.. might be very usefull to know the basics:

    good books about C++


    if helped dont forget to "Rate this post"
    It takes seconds for rating…that actually compensates the minutes taken for giving answers
    The biggest guru-mantra is: Never share your secrets with anybody. It will destroy you.
    Regards, Be generous->Rate people
    Jayender!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured