hi guys^^
I wanna to write a program like this in c++:
get the weight of n bag and then calculate the minimum cost for n bag in a bag.
( in first line get n number and in second line get n numbers and then print the minimum cost)
If there is only one bag, integration cost is zero!
Lines 6,9: Why are you doing a cin >> num twice? Did you mean to input price?
PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post. http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.
@AbstractionAnon
Hi, thank you , i got correct my post ^_^
i wrote two cin>>num because of this => in first line get n number and in second line get n numbers
and my mean of num is weight
my program not correct, i can't see correct output
please help me
thanks
@DrZoidberg
Hi, i changed to price but i can't see output
My program get out in immediately,i can't see result
even i wrote getchar but was not true ((
get the weight of n bag and then calculate the minimum cost for n bag in a bag.
( in first line get n number and in second line get n numbers and then print the minimum cost) If there is only one bag, integration cost is zero!
Your problem statement is not clear. What does "for n bag in a bag" mean?
"integration cost" - What is this?
Please explain how you arrived at an output of 108 given the 5 numbers above.
Your program, as written, only reads two values (num and price).
@AbstractionAnon
I wanna to get sum of the weight of n bag in a bag
My mean of that example is first number print in first line and then other numbers print in second line and finally print sum of the weight of n bag
I suspect it exits because you're trying to enter multiple values but are only reading one when getting price. cin uses spaces and newlines as delimiters, so getchar() doesn't have to wait for additional input when you enter "4 23 ..." - it just gets the first character after the first space.
If you want to read multiple values in one line use the std::getline function
Running the program from the command prompt will allow you to see the output even after it terminates. Won't fix the problem, but it could help you understand what's going on
That said, I don't really understand how you got 108