C++ beginner/student - coding errors


#1

I'm am student that has basic knowledge in HTML and CSS. I've been doing an online C++ class that's proving to be a lot difficult than I thought it would be. It's been almost impossible to find a tutor for this language. I'm seeking help with an assignment (shown below). I keep getting error messages no matter how I display the if/else statements, as well as setting the constants.

The assignment:

You have a book club that awards discounts to the purchasers of books based on the number of books they purchase. Discounts are awarded as follows.

Points
Books Purchased Points Awarded
0 0
1 2%
2 4%
3 6%
4+ 10%
Your program should only ask the user for the number of books purchased, everything else is fixed for this program

The Book: Advanced C++ Programming by Gaddis,
The Store Price: $39.95

Display the sale as:

Name: The actual name of the book from above

Discount awarded as a percent
Store Cost:
Discount Amount:


Final Cost:


#2

Please, post your code. Or you want complete solution for this issue?


#3

I am working with the similar assignment. So far i have this but in the output its giving some long number like 431023 instead of the output i need.

include

int main()
{
int books;
const int storeCost = 39.95;
int discountAwarded;

std::cout << "Enter The Number Of Books Purchased: ";
std::cin >> books;
std::cout << "Name: Advanced C++ Programming by Gaddis\n";
std::cout << "Store Cost: " << storeCost <<std::endl;

if(books == 0)
{
std::cout << "Discount Awarded: " << discountAwarded <<std::endl;
discountAwarded = 0.00;
}
if(books == 1)
{
std::cout << "Discount Awarded:" << discountAwarded <<std::endl;
discountAwarded = 0.02;
}
if(books == 2)
{
std::cout << "Discount Awarded: " << discountAwarded <<std::endl;
discountAwarded = 0.04;
}
if(books == 3)
{
std::cout << "Discount Awarded: " << discountAwarded <<std::endl;
discountAwarded = 0.06;
}
if(books >= 4)
{
std::cout << "Discount Awarded:" << discountAwarded <<std::endl;
discountAwarded = 0.10;
}
else
{
if(books < 0)
std::cout << "Number of books cannot be negative!! \n\n";

}
}


#4

@denys.matsevych @rsoler5335 Thanks for responding. The code that I had so far is as below:

include

include

using namespace std;

int main ()
{

// Constants for book prices

int text_book = (39.95);
int book_0 = (0);
int book_1 = (2/100);
int book_2 = (4/100);
int book_3 = (6/100);
int book_4 = (10/100);

if true (books==0)
{ discount = text_book * book_0;
final_cost = text_book - discount;
points = book_0;
}
else if (books == 1)
{ discount = text_book * book_1;
final_cost = text_book - discount;
points = book_1;
}
else if (books == 2)
{ discount = text_book * book_2;
final_cost = text_book - discount;
points = book_2;
}
else if (books == 3)
{ discount = text_book * book_3;
final_cost = text_book - discount;
points = book_3;
}
else if (books == 4)
{ discount = text_book * book_4;
final_cost = text_book - discount;
points = book_4;
}

cout << " Please enter the number of books purchased:" << endl;
cout << "Name: Advanced C++ Programming by Gaddis\n";
cout << "Store Cost: " << final_cost <<std::endl;
return 0;
}