Barnes & Noble has a book club that awards points to its customers based on the
ID: 3528581 • Letter: B
Question
Barnes & Noble 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 purchase 0 books, he or she earn 0 points. If a customer purchase 1 books, he or she earn 5 points. If a customer purchase 2 books, he or she earn 15 points. If a customer purchase 3 books, he or she earn 30 points. If a customerpurchase4 or more books, he or she earns 60 points. Create a console application that lets the users to enter the number of books she or he has purchased this month and displays the number of points earned. If the user enters a negative number, display an error message and prompt the user again until the input is validExplanation / Answer
//please rate fairly
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Points
{
class Points
{
static void Main(string[] args)
{
int books;
int points;
//get valid books
do
{
Console.Write("Enter number of books purchased this month: ");
books = int.Parse((Console.ReadLine()));
if (books < 0) {
Console.WriteLine("Error: You cannot purchase negative books!");
}
} while (books < 0);
//set points accordingly
switch (books) {
case 0:
points = 0;
break;
case 1:
points = 5;
break;
case 2:
points = 15;
break;
case 3:
points = 30;
break;
default:
points = 60;
break;
}
//output result
Console.WriteLine("This month, you earned {0} points.", points);
Console.ReadLine(); Console.ReadLine(); //stall compiler from closing for 2 line reads
}//end main
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.