I am making a program that calculates the price of apples (its a school one). To throw in a twist they made it so when you buy one apple you get one free. I am not aloud to use the "if" feature in this program. It is driving me crazy, I don't know how to make it so when I buy 3 apples it shows up as 2 dollars because of this whole buy one get one free thing.
Here is the code I have so far.
Code:
#include <cstdlib>
#include <iostream>
#include <string>
using namespace std;
double apple (double first,double second);
int main(int)
{
//vars
string username; //Users name.
double usra,usrap=1.00; //Users choice of Appales.
double usro,usrop=1.50; //Users choice of Oranges.
double applecal; //Apple calculations.
double orangecal; //Orange calculations.
//vars end
//sig
cout<<"*********************************************************"<<endl;
cout<<"* *"<<endl;
cout<<"* Nicks Grocery store *"<<endl;
cout<<"* *"<<endl;
cout<<"*********************************************************"<<endl;
cout<<endl;
//sig end
//Program
cout<<"Welcome to Nick's Grocery Store."<<endl;
cout<<endl;
cout<<"****Todays Specials.*****"<<endl;
cout<<"*Buy one Apple get one *"<<endl;
cout<<"*free! *"<<endl;
cout<<"*-----------------------*"<<endl;
cout<<"*Each Orange you buy *"<<endl;
cout<<"*deducts 1% off your *"<<endl;
cout<<"*bill. *"<<endl;
cout<<"*************************"<<endl;
cout<<"Max of 100 items per customer"<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
cout<<endl;
//Asks for Users name.
cout<<"Enter your name :";
cin>>username;
cout<<endl;
//Asks how many Apples the User wants.
cout<<"How many Apples would you like "<<username<<" :";
cin>>usra;
cout<<endl;
//Asks how many Oranges the User wants.
cout<<"How many Oranges woukd you like "<<username<<" :";
cin>>usro;
cout<<endl;
cout<<"*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*"<<endl;
applecal= apple(usra,usrap);
cout<<applecal<<endl;
//Program end
}
double apple(double first,double second)//Math for Apples
{
return first*second;
}