DevX Home Today's Headlines   Articles Archive   Tip Bank   Forums

# Thread: Grocery Store-School project

1. Registered User
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. Registered User
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)

#### Posting Permissions

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

 FAQ Latest Articles Java .NET XML Database Enterprise
 Questions? Contact us. C++ Web Development Wireless Latest Tips Open Source

Top DevX Stories