I need help writing a c++ program for these two problems thanks. 13. Book Club P
ID: 3670477 • Letter: I
Question
I need help writing a c++ program for these two problems thanks. 13. Book Club Points Serendipity Booksellers has a book club that awards points to its customers based on the number of books purchased each month. The points are awarded as follows If a customer purchases 0 books, he or she earns 0 points If a customer purchases 1 book, he or she earns 5 points. If a customer purchases 2 books, he or she earns 15 points. If a customer purchases 3 books, he or she earns 30 points. If a customer purchases 4 or more books, he or she earns 60 points Write a program that asks the user to enter the number of books that he or she has purchased this month and then displays the number of points awarded. 18. Fat Gram Calculator Write a program that asks for the number of calories and fat grams in a food. The pro- gram should display the percentage of calories that come from fat. If the calories from fat are less than 30% of the total calories of the food, it should also display a message indicating that the food is low in fat. One gram of fat has 9 calories, so Calories from fat = fat grams * 9 The percentage of calories from fat can be calculated as Calories from fat ÷ total calories Input Validation: Make sure the number of calories and fat grams are not less than 0. Also, the number of calories from fat cannot be greater than the total number of calories. If that happens, display an error message indicating that either the calories or fat grams were incorrectly enteredExplanation / Answer
//Question -13 c++ program
/*C++ program that prompts user to enter the number of books purhcased
for the montha and finds the number of points earned for purchased books.
Then print the books and points earned.*/
#include<iostream>
using namespace std;
int main()
{
cout<<"BOOK CLUB POINTS"<<endl;
//declare integer variables for books and points
int books;
int pointsawarded=0;
//points awarded for number of books
const int ZERO_BOOKS=0;
const int> const int TWO_BOOKS=15;
const int THREE_BOOKS=30;
const int FOUR_BOOKS=60;
cout<<"Enter the number of books purchased this month : ";
//read books
cin>>books;
//Check if books are zero
if(books==0)
pointsawarded=ZERO_BOOKS;
//Check if number of books is one
else if(books==1)
pointsawarded=ONE_BOOKS;
//Check if number of books is two
else if(books==2)
pointsawarded=TWO_BOOKS;
//Check if number of books is three
else if(books==3)
pointsawarded=THREE_BOOKS;
//Check if number of books more than four books
else if(books>=4)
pointsawarded=FOUR_BOOKS;
//print the points awared to books purchased
cout<<"Number of points earned for purchasing "<<books
<<" books is "<<pointsawarded<<endl;
system("pause");
return 0;
}
--------------------------- --------------------------- ---------------------------
Sample Output:
BOOK CLUB POINTS
Enter the number of books purchased this month : 5
Number of points earned for purchasing 5 books is 60
-----------------------------------------------------------------------------------------------------------------
//Question -18 c++ program
/*C++ program that prompts user to enter the number of calories and number of fat grams.
Then calculates number of fat calories and percentage of fat calories and check
if fat calories are less than number of calories then print food is low fat
otherwise print food is high fat.*/
#include<iostream>
using namespace std;
int main()
{
//Set a constant for fat calroies for one gram
int FAT_ONE_GRAM=9;
//declare variabels to read number of variables and fat grams
double numCalories;
int fatGrams;
//ste fatCalories=0;
double fatCalories=0;
do
{
//read number of caloreies
cout<<"Enter number of calories : ";
cin>>numCalories;
if(numCalories<0)
cout<<"Invalid number of calories entered."<<endl;
}while(numCalories<0);
do
{
//read number of fat grams
cout<<"Enter number of fat grams : ";
cin>>fatGrams;
if(fatGrams<0)
cout<<"Invalid number of calories entered."<<endl;
}while(fatGrams<0);
fatCalories=FAT_ONE_GRAM*fatGrams;
//Check if fat calories more than number of calories
if(fatCalories>numCalories)
{
cout<<"Either number of caloreis or fat grames are incorrectly entrered."<<endl;
system("pause");
return 0;
}
//find the percentage of fat
double fatPercentage=(fatCalories/numCalories);
//Check if fatCaloreis are less than the 30 percent of numCalories
if(fatCalories<numCalories*(0.3))
{
cout<<"Food is low in fat"<<endl;
}
else
cout<<"Food is high in fat"<<endl;
//pause the program output on console until user enters a key.
system("pause");
return 0;
}
------------------------ ------------------------ ------------------------ ------------------------
Sample output:
Enter number of calories : 50
Enter number of fat grams : 2
Food is high in fat