im sorry to have to post for something like this but i am desperate.
in what .h can the round() function be found? again, im sorry to have to make a new thread for something like this :/
im sorry to have to post for something like this but i am desperate.
in what .h can the round() function be found? again, im sorry to have to make a new thread for something like this :/
while you're at it ( )
how can i, for example, define an array with an user-defined size?
as in, i need a proggy in which the user inputs the number of "digits" in the array, and then defines each
only thing that comes to mind is make something like:
1. tell the user to enter the # of values he wants the array to consist of.
2. tell the user to enter all the values, and each time he enters a value, lets say, i use a counter to count the # of values he used.
only problem is, how then do i arrange those values in the array?
ive tried declaring a variable n so the user lets the proggy know how many values he will use, but then i cant declare an array like w[n] cause it says:
[quote]expected constant expression
cannot allocate an array of constant size 0
'w' : unknown size]
:/ any help, id appreciate it
the early bird gets the worm but the second mouse gets the cheese
compiler?
but most likely you will need to use new and delete to allocate memory.
for example:
Code:int *array; int size; std::cin >> size; array = new int[size];
using MS Visual c++
this is what i got so far:
Code:#include <iostream.h> #include <math.h> int main() { int n; cout << "Enter the number of values to process:\n"; cin >> n; while(n<0){ cout << "Enter the number of values to process:\n"; cin >> n; } if(n==0) cout << "No values to process.\n"; if(n>0){ cout << "First Value:\n"; cin >> w[0]; } for(int i=1;i<n;i++){ cout << "Next Value:\n"; cin >> w[i]; } return 0; }
the early bird gets the worm but the second mouse gets the cheese
you haven't declared your array.
whoa
you helped
the early bird gets the worm but the second mouse gets the cheese
yeah i took it out to show the code: i didnt want peeps to mock me for my n00b skillz ;/
the early bird gets the worm but the second mouse gets the cheese
it workedCode:#include <iostream.h> #include <math.h> int main() { int n, *w; cout << "Entrar el numero de datos a procesar:\n"; cin >> n; w = new int[n]; while(n<0){ cout << "Entrar el numero de datos a procesar:\n"; cin >> n; } if(n==0) cout << "No hay datos para procesar.\n"; if(n>0){ cout << "Primer Numero:\n"; cin >> w[0]; } for(int i=1;i<n;i++){ cout << "Proximo Numero:\n"; cin >> w[i]; } return 0; }
the early bird gets the worm but the second mouse gets the cheese
we're not here to mock you. we understand that you and others may be newbies. I'm still sortof a newbie. we're here to help.Originally posted by vege^
yeah i took it out to show the code: i didnt want peeps to mock me for my n00b skillz ;/
I'm glad I could help
oh i almost forgot: where's the round() function
i mean, what #include do i have to do in order to use it :/
the early bird gets the worm but the second mouse gets the cheese
on your above code, add this line before return 0;
as for the round() fxn. i don't know. have you tried msdnCode:delete []w;
actually, there are some round fxns in math.h .
edit: i hope its what you're looking for. so #include <math.h>
to round a float/double to nearest int try.....
int x = floor( your_float_or_double + 0.5 );
That will round to nearest int. You can wrap that in its own function no problem.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
the round function im looking for rounds a number to 2 decimal places
the professor gave us this example:
but when i try to make a function like thisCode:round(x*100)/100
it says something about double/int conversions, but even if i change it to double, when i summon the function in the program it still gives me the double/int error :/Code:int round(int x){ int r; r=(x*100)/100; return r; }
any thoughts?
You can still use what i gave you with some creative multiplication and division no problem. Its easy to move a decimal point isnt it.
Free the weed!! Class B to class C is not good enough!!
And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi
i am teh dumb :/
if i have:
how then would i round d to 2 decimal places using what you gave me? sorry im bothering so much :/Code:a=minValue(w,n)-.01; b=maxValue(w,n)+.01; d=(b-a)/5;