May 15th, 2013, 10:46 PM
I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.
using namespace std;
cout<<"What is the original price?";
cout<<"What is the discount?";
cout<<"What is the tax?";
cout<<"The total is"<<original_cost*discount+original_cost*tax-discount;
cout<<"Do you want to try again?";
May 16th, 2013, 04:11 AM
Re: C++ Program
I do NOT see any "calculation" in the code snippet you have posted. Perhaps, it is the reason why "the answer is wrong"?
Originally Posted by gamesun
Besides, you have to use Code tags while posting code snippets. Please, read the Announcement: Before you post.... (see section "Information on posting")
May 16th, 2013, 06:44 AM
Re: C++ Program
This is not really what you mean.
This tests if answer is 'Y' or 'y' is non-zero (which it always is). So this statement is always true. In c/c++ you have to formulate the tests correctly and not as you would say in English. The correct code would be
For the calculation,
} while(answer == 'Y' || answer == 'y');
Multiplication takes precedence over addition, so this statement evaluates as
original_cost * discount + original_cost * tax-discount;
Hope this helps.
(original_cost * discount) + (original_cost * tax) - discount;
All advice is offered in good faith only. You are ultimately responsible for effects of your programs and the integrity of the machines they run on.
Tags for this Thread
Click Here to Expand Forum to Full Width
This is a CodeGuru survey question.