Jan 31, 2015 at 7:56pm UTC
Hi,
there is a bug either in the script or answer,
if i run a compiler i get 154 as an answer
(Enter price: 22,25 Enter quantity: 7 Total price: 154),
not 155,75.
best regards
Last edited on Jan 31, 2015 at 8:14pm UTC
Jan 31, 2015 at 8:05pm UTC
Really? No code? What do you expect us to help you with?
Edit: Actually I see your issue but in the future don't post such a descriptionless problem with no code like this.
The problem is you are using an int instead of a float. Ints can only be whole numbers, so 7*22.25 changes to 7*22 which = 154
Use floats instead of ints
Last edited on Jan 31, 2015 at 8:06pm UTC
Jan 31, 2015 at 8:07pm UTC
We need more information to help. You've posted the input, expected output, and the actual output that you're receiving. Those are definitely useful, but you need to post your code also.
When you post code, please put it in code tags. Enter the code, then look at the right side of the input window. Highlight the code and click the <> button at right.
Jan 31, 2015 at 8:14pm UTC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
// stringstreams
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main ()
{
string mystr;
float price=0;
int quantity=0;
cout << "Enter price: " ;
getline (cin,mystr);
stringstream(mystr) >> price;
cout << "Enter quantity: " ;
getline (cin,mystr);
stringstream(mystr) >> quantity;
cout << "Total price: " << price*quantity << endl;
return 0;
}
and on the right side of display stands 155,75
http://www.cplusplus.com/doc/tutorial/basic_io/
Last edited on Jan 31, 2015 at 8:20pm UTC
Jan 31, 2015 at 8:16pm UTC
Please mark as answered if your question was answered. :)
Jan 31, 2015 at 9:53pm UTC
I assume you are inputting the value as 22,25 but you need to input it as 22.25
Feb 1, 2015 at 7:31am UTC
Yes, so is it. Thank you..