DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    May 2007
    Posts
    2

    Grocery Store-School project

    I am currently taking a C++ course so I'm a novice. I am trying to complete this project that is giving me much frustration. I am not allowed to use If statements or any loops, which makes it more difficult. here is the code:

    Code:
    #include <iostream>
    using namespace std;
    float Apple(int numA);
    double Orange(double numO);
    int main()
    {	int Apples;
    	int Oranges;
    	
    	cout << "Welcome to the Apples N' Oranges Grocery" << endl;
    	cout << "Apples are $1.00, oranges are $1.50"	<< endl;
    	cout << "Special on apples, 2 for 1!" << endl;
    	cout << "and, special on oranges, for every orange ordered you get that percent off purchase." << endl;
    	cout << "How many Apples would you like?(must be between 1 and 100)" << endl;
    		cin >> Apples;
    	cout << "How many Oranges do you want?(must be between 1 and 100)" << endl;
    		cin >> Oranges;
    	cout << "You have " << Apples << " apples and " << Oranges << " oranges."<< endl;
    	cout << "Your subtotal is $" << Apple(Apples) + Orange(Oranges) << endl;
    	double discount = (Apple(Apples) + Orange(Oranges)) * (Oranges/100);
    	double Total =  (Apple(Apples) + Orange(Oranges))- discount;
    	cout << "Discount $" << discount << endl;
    	cout << "Grand total is $" << Total << endl;
    	return 0;
    	system("PAUSE");
    }//The following function gives the price of apples.
    float Apple(int numA)
    {	
    	int priceA = numA%2;
        priceA = priceA + (numA/2);
    	return priceA;
    }
    //This function calculates the price of oranges.
    double Orange(double numO)
    { 
    	return 1.50 * numO;
    }
    The discount will not calculate and i need to know why. plz help me.
    Last edited by Uchihanokonoha; 05-14-2007 at 01:33 AM.

  2. #2
    Join Date
    May 2007
    Posts
    2
    Never mind, it was simply a matter of adding a decimal place to 100 so instead of (oranges/100), it was (oranges/100.0)

Similar Threads

  1. Control Arrays in VB.NET
    By Gary Nelson in forum .NET
    Replies: 277
    Last Post: 10-01-2003, 12:00 AM
  2. Good Editorial by Russell Jones
    By Robert G in forum .NET
    Replies: 84
    Last Post: 02-08-2001, 02:38 PM
  3. Replies: 0
    Last Post: 09-13-2000, 10:18 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links