|
Thanks. I'm finally getting the hang of it. I'll try something tomorrow and I will let you peoples know if I succeed or not.
|
|
|
|
|
|
Thanks again, I make improve in the code, but it ain't working as supposed.
I'm really wondering where the code is wrong, I get no output or a wrong output (e.g. 100 100 100 gives as output only 100 a, 0 b, 0 c.)
I tried different things and I guess I'm almost there, but can't fix it.
So please, help me with this code.
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[])
{
int a, b, c, x, y, z;
printf("price of a:\n");
printf("price of b:\n");
printf("price of c:\n");
scanf("%d, %d, %d" ,&a, &b, &c);
for(x = 0; x <= 100; x++)
{
for(y = 0; y <= (100 - x); ++y)
{
z = 100 - x - y;
if(x*a + y*b + z*c == 10000)
{
printf("%d a, %d b, %d c",x ,y ,z);
}
}
}
return 0;
}
|
|
|
|
|
You don't use correctly scanf . Try
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int main(int argc, char *argv[])
{
int a, b, c, x, y, z;
int done = 0;
while ( done == 0)
{
printf("please enter the price of a:\n");
if ( scanf("%d", &a) != 1) continue;
printf("please enter the price of b:\n");
if ( scanf("%d", &b) != 1) continue;
printf("please enter the price of c:\n");
if ( scanf("%d", &c) != 1) continue;
done = 1;
}
for(x = 0; x <= 100; x++)
{
for(y = 0; y <= (100 - x); ++y)
{
z = 100 - x - y;
if(x*a + y*b + z*c == 10000)
{
printf("%d a, %d b, %d c\n",x ,y ,z);
}
}
}
return 0;
}
|
|
|
|
|
Thank you so much! It works great. I had to change the code a bit to pass all testcases, but finally I made it .
However, I'd like to know how that piece of code between the While { ... } works, I don't really get it.
done = 0, so while ( done == 0) is true. Then it runs the code and you can enter the values. But why does it need the done == 0 and why the != 1? I understand the done = 1, otherwise it will run the while statement again, right?
|
|
|
|
|
Well, I don't know why it did not work the first time, but I tried to simplify the code and ended up with:
printf("price of a: price of b: price of c: ");
scanf("%d %d %d", &a, &b, &c);
instead of that thing with while { ... }
And this time, it did work. I do not really see the difference with the code I used before that did not work.. :p
|
|
|
|
|
Even the code you used before would have work with a suitable input, that is if the user would have entered, for instance
100,100,100
that is, with the commas.
However, the code handling input from the user should be more robust.
|
|
|
|
|
Perhaps your problem can be broken up into two smaller problems: 1) Find all combinations of A+B+C that equal (quantity) 100. I *think* that gives you a set of about 4851 combinations. 2) For each of those, multiply A by 0.88, b by 0.99, and C by 1.02, and if that product equals 100 euros, you have a match.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
That sounds like a faster way to calculate, because of the smaller set of combinations. I'd like to try that another time, but I don't have the time to do that now before the deadline. Thanks for the tip, nice to see how there are multiple solutions to work it out.
|
|
|
|
|
Hi all,
I need callback functions between different classes. I had already a solution based on stl, which was compilable with VS2010. Unfortunately I was not able to find a way to compile it with VS2015. I got weird error messages.
Now I found a solution with lamda C++11 lambda function pointers. Actually it works, but I have one open issue.
For having a save source code, I want to initialize the function pointer with NULL. But compiler is producing weird error messages again!
My Code:
typedef std::function<bool(int, int, CString*)> _tcedit_cb_;
class MyClass
{
public:
MyClass ()
{
m_cbGetItemData = NULL;
}
_tcedit_cb_ m_cbGetItemData;
...
}
How I can initialize the function callback pointer? I need to initialize in order to avoid running into illegal code!
e.g. I tried to cast ... = (_tcedit_cb_) NULL;
error messages:
c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : error C2893 : Failed to specialize function template 'unknown-type std::invoke(_Callable &&,_Types &&...)'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : With the following template arguments :
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Callable=_Decayed &'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\type_traits(1501) : note : '_Types={int, int, ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t>>> }'
1> c:\program files(x86)\microsoft visual studio 14.0\vc\include\functional(210) : note : see reference to function template instantiation '_Rx std::_Invoke_ret<_Rx,_Callable&,_Ty,_Ty,ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t>>>>(std::_Forced<_Rx,false>,_Callable &,_Ty &&,_Ty &&,ATL::CStringT<wchar_t,StrTraitMFC<wchar_t,ATL::ChTraitsCRT<wchar_t>>> &&)' being compiled
1> with
1>[
1> _Rx = bool,
1> _Callable = _Decayed,
1> _Ty = int
1>]
|
|
|
|
|
Here's a stab in the dark:
Instead of initializing to NULL , try setting it to nullptr .
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
oh....you are right!
with nullptr it works!!! never, never used it before!
Many Thanks
Richard
|
|
|
|
|
The objective is to compare the performance of different data structures and algorithm.
The Task= in order to evaluate different ADTs an evaluation with large data must be conducted. Each ADTs should be implememted using any programming language.
choosing a dataset consist of 1000, 10,000, 50,000, 100,000, and 1,000,000 data for evaluation by using random numbers generators.
observations include (a). complexity in creating/building ADTs for the data
(b). complexity to perform insertion, deletion, and search.
the ADTs are .
conduct simple experiment to compare the performance of the different ADts.
are:
Array
Linked List
Stack
Queue
modified 10-Sep-15 16:45pm.
|
|
|
|
|
So what is the question? If the purpose is to calculate the time taken only, then consider using the clock of <ctime> header. Then calculate the time taken to complete the task, pass different number of parameters to it and see the results.
#include <iostream>
#include <ctime>
int main() {
unsigned int start = clock();
your_function(param);
std::cout << "Time taken in millisecs: " << clock()-start;
return 0;
}
This is a native way of doing so, but I would recommend that you try using the API which so ever OS you are using, for example on Windows there are many ways to get the service of a stopwatch in Win32 or even better in Visual C++'s .NET implementation.
Above code from: http://cboard.cprogramming.com/cplusplus-programming/97572-how-do-stopwatch-cplusplus-program.html[^]
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
thanks. but its not just about the time taken only. i updated the questions. please do check again and give me your idea. its killing me here. am confused
|
|
|
|
|
What do you mean with ADT?
|
|
|
|
|
Presumably, abstract data type.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
I believe you are right, however I wonder how could you measure the performance of an abstract data type?
|
|
|
|
|
CPallini wrote: I wonder how could you measure the performance of an abstract data type?
Reading it seemed pretty obvious to me that point it to measure the performance of the data structures when they contain the ADTs with the given functional methods
|
|
|
|
|
See #11 here.
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Member 11975120 wrote: The objective is
Solution:
1 - Write a ADT
2 - Create method to populate ADT with random data using a fixed seed.
3 - Write data structures.
4- Write method that creates number of ADTs and creates data structure with number given
5- Write method that inserts, searches and deletes a single newly create ADT
6- Make sure all of that works
7- Add timing to 5 and write times out
|
|
|
|
|
Good afternoon friends. Please how do I make this program quoted the following link function in the virtualbox, for example I downloaded the tutorial and no disk image or anything. Please for I am beginner and I am interested in the subject of freestanding but do not find anything on the web. If someone can help me thank you or not. Already Obrigadoe God Bless ...
|
|
|
|
|
Which link are you referring to? If it is from a CodeProject article then please use the forum at the end of the article.
|
|
|
|
|
Good Night, and Deculpa Friend, forgot the link but here goes: http: //www.codeproject.com/Articles/36907/How-to-develop-your-own-Boot-Loader
|
|
|
|
|
OK, so post your question in the forum below the article.
|
|
|
|
|