/* Jagrut Patel
   Ecor 1606
   Assignment 3
   Question 2: Suggest food and drinks based on the amount of money entered by user */

#include <iostream>
#include <cmath>
#include <iomanip>
#include <cstdlib>

using namespace std;

bool isInt (double value) {
    double dummy;
    return bool(modf(value, &dummy) == 0);
}

double sqr(double value) {
    return value * value;
}

int main (void) {

    // Variables
    double aFood;
    double aDrink;
    double costFood;
    double costDrink;
    double totalCost;
    double expCost;
    double caloriesDrink;
    double caloriesFood;
    double vitaminCdrink;
    double vitaminCfood;
    double avgvitaminC;
    double totalvitaminC=0;
    double totalvitaminCmeal=0;
    double totalCalories;
    double leastCalories;
    double count=0;
    double economicalvitaminC=0;
    double overCalories=0;
    double notafford=0;//tracks when user cannot afford anything

    // Asks user to enter the amount of money they have
    cout << "Enter the amount of money you have"<<endl<<"available for Food and Drink(0 0 to stop): ";
    // Stored the entered amount of money into aFood and aDrink
    cin >> aFood>>aDrink;
    
    
        
    //loop will continue as long as user enters value greater than 0 for both food and drink
	while (aFood!=0||aDrink!=0){
		//loops used to make sure the input values are valid
		if (aFood<0||aDrink<0){
    	cout<<"The value for the amount of money available must be positive!"<<endl;
    	    
    	}
    
		
		else {
			//keeps track of how many times the loop has been repeated
			count++;
			/* if statements used to decide which aDrink user should buy based on the amount of money.
       		Each statement in the respective if/ else if statements are carried out when it's expression is true */
			if (aFood>=24.00){
				caloriesFood=300;
				vitaminCfood=148;
				costFood=24.00;
				cout<<"You could buy the Steak & Broccoli for $24.00";
			}
			
			else if(aFood>=14.99){
				caloriesFood=80;
				vitaminCfood=30;
				costFood=14.99;
				cout<<"You could buy the Veggie Platter for $14.99";
			}
				
			else if(aFood>=6.75){
				caloriesFood=200;
				vitaminCfood=9;
				costFood=6.75;
				cout<<"You could buy the Submarine Sandwich for $6.75";
			}
			
			else if(aFood>=3.50){
				caloriesFood=250;
				vitaminCfood=6;
				costFood=3.50;
				cout<<"You could buy the Pepperoni Pizza for $3.50";
			}
			
			else if(aFood>=2.50){
				caloriesFood=301;
				vitaminCfood=12;
				costFood=2.50;
				cout<<"You could buy the All dressed hamburger for $2.50";
			}
			
			else if(aFood>=1.00){
				caloriesFood=452;
				vitaminCfood=2;
				costFood=1.00;
				cout<<"You could buy the Doughnuts for $1.00";
			}
			
			else if(aFood>=0.35){
				caloriesFood=436;
				vitaminCfood=0;
				costFood=0.35;
				cout<<"You could buy the Noodle Soup for $0.35";
			}
		
			else {
				cout<<"You don't have enough money for food!";
				notafford++;
			}
			
			cout<<endl;
			
			/* if statements used to decide which aDrink user should buy based on the amount of money.
	       Each statement in the respective if/ else if statements are carried out when it's expression is true */
			if (aDrink>=8.99) {
				caloriesDrink=101;
				vitaminCdrink=236;
				costDrink=8.99;
    	    	cout << "You could buy the Orange Juice with Carrots & Spinach for $8.99";
    		} 
			
			else if (aDrink>=4.99) {
    			caloriesDrink=112;
    			vitaminCdrink=207;
    			costDrink=4.99;
        		cout << "You could buy the Orange Juice for $4.99";
    		}
			
			else if (aDrink>=3.50) {
    			caloriesDrink=203;
    			vitaminCdrink=50;
    			costDrink=3.50;
        		cout << "You could buy the Asparagus Milkshake for $3.50";
    		}
			
			else if (aDrink>=2.50) {
    			caloriesDrink=250;
    			vitaminCdrink=149;
    			costDrink=2.50;
        		cout << "You could buy the Strawberry Milkshake for $2.50";
    		}
			
			else if (aDrink>=1.75) {
    			caloriesDrink=2;
    			vitaminCdrink=7;
    			costDrink=1.75;
        		cout << "You could buy Tea for $1.75";
    		} 
			
			else if (aDrink>=1.25) {
    			caloriesDrink=0;
    			vitaminCdrink=0;
    			costDrink=1.25;
        		cout << "You could buy Water for $1.25";
    		} 
			
			else if (aDrink>=0.25) {
    			caloriesDrink=0;
    			vitaminCdrink=0;
    			costDrink=0.25;
        		cout << "You could buy Coffee for $0.25";
        		// Outputs error message if the amount of money entered is negative
    		}
			
			else {
        		cout << "You don't have enough money for a drink!";
        		notafford++;
    		} // end if
    	
    		if (notafford!=2){//done if user cannot afford anything
    			
    		    
    			//calculates the total Cost, Calories and Vitamin C of the meal
       			totalvitaminC=vitaminCfood+vitaminCdrink;
    			totalCalories=caloriesFood+caloriesDrink;
    			totalCost=costFood + costDrink;
    	
    			//if statement used to find the most economical source of Vitamin C based on cost of the meal
    			if (count==1||economicalvitaminC<totalvitaminC/totalCost){
    		
    				economicalvitaminC=totalvitaminC/totalCost;
    			}
    	
 				//keeps track of how many meals had calories over 650   	
    			if (totalCalories>650){
    				overCalories++;
				}
    		
    			//determines the most expensive mela
				if (count==1||totalCost>expCost){
					expCost=totalCost;
				}
		
				//determines the meal with the least calories
				if (count==1||totalCalories<leastCalories){
					leastCalories=totalCalories;
				}
		
				//prints out the respective statistic for each meal
    			cout<<endl<<"The cost of the meal is $"<<totalCost<<endl;
    			cout<<"The total calories of the meal is "<<totalCalories<<endl;
    			cout<<"The meal has "<<totalvitaminC<<"% of the daily required Vitamin C"<<endl;
    	
    			//keeps track of the total vitamin C unti user enters (0,0)
    			totalvitaminCmeal=totalvitaminCmeal+totalvitaminC;
    	
			}//endif
			else {notafford--;
			}
		}//end if
		notafford=0;//resets the variable to 0 to track when user can't afford both food and drink
		cout <<endl<< "Enter the amount of money you have"<<endl<<"available for Food and Drink(0 0 to stop): ";
    	// Stored the entered amount of money into aFood and aDrink
    	cin >> aFood>>aDrink;
		
	}//endwhile
	
	
	//if statement used to make sure stats are only outputted when valid, atleast one meals was ordered
	if (count>0){
		
		//calculates the average vitamin C of all the meals ordered
		avgvitaminC=totalvitaminCmeal/count;
		
		cout<<endl<<"The most expensive meal costs: $"<<expCost<<endl;
		cout<<"The meal with the least calories had: "<<leastCalories<<" calories"<<endl;
		cout<<"The average vitamin C per meal was: "<<trunc(avgvitaminC)<<endl;
		cout<<"The most economical source of Vitamin C was: "<<trunc(economicalvitaminC)<<"%/dollar"<<endl;
		cout<<trunc(overCalories/count)<<"% of the meals had more than 650 calories."<<endl;
	}
	
	//else used to print out statement when no meals are ordered
	else {
		cout<<"No valid statistics can be shown due no meals being ordered!"<<endl;
	}//endif
	
	
	
	system("PAUSE"); return 0;

}//end of program
