Hi guys, so I'm working on this simply lab and everything seems to work fine when I build the solution. The problem is that when I select "start with out debugging" the questions come out all at once.
#include<iostream>
#include<iomanip>
//////////////////
// Add any other libraries you need to include
//////////////////
using namespace std;
int main()
{
// The variables you will use for this program.
// You may not use any other variables or change the type
// of these variables
int price; // The price for the quantity specified by the grocery store
int quantity; // The quantity specified by the grocery store
int amount; // The amount of the product that you wish to purchase
double cost; // The cost for the number of the product that you purchase
// Ask the user to enter the price per quantity and the amount
// she would like to purchase
cout << "What is the given price? " << endl;
cin >> price;
When I run your code, it waits for me to enter value before going on to the next question. Here is a sample run.
What is the given price?
3
For what quantity?
4
What amount do you wish to purchase?
5
The cost will be:0
In standard money format:0.00
If you get different behaviour, I suspect that what you're running is not actually the code above or there's something wrong with your input mechanism.
You're going to have a problem with this line: cost = (price/quantity)*amount;
price and quantity are int values, and an int divided by an int will give you another int. If price is less than quantity, then price/quantity will come out as zero. Convert them to double or float before doing this calculation.
Just out of curiosity, why do you ask for a price and then 2 quantities?
1 2 3 4 5 6 7 8
cout << "What is the given price? " << endl;
cin >> price;
cout << "For what quantity? " << endl;
cin >> quantity;
cout <<"What amount do you wish to purchase?" << endl;
cin>> amount;
and then do
1 2 3 4
// Calculate the cost for the amount the user would like to purchase
cost = (price/quantity)*amount;
I'm not sure I understand why your dividing the price by a quantity and then multiplying it by another quantity.
I'm probably over looking something but just seems a little off to me.
PS you didn't have to convert all your int's to doubles, price and cost probably, but you could have used the static_cast to temporarily convert your int's to doubles for your calculations.
@torind2000:
For what given price means the price is for how many units of the object.
For example:
Given Price is 150.
Quantity is 10.
That means, the price 150 is for 10 objects.