|
Hi:
Thank you very much for your help. I really appreciate it.
Thank you
|
|
|
|
|
// Console.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <shlwapi.h>
#pragma comment(lib, "shlwapi.lib")
int main(int arvc, char* argv[])
{
LPCTSTR pFileName = PathFindFileName("C:Program Files/Local_user/Visual Studio 2005/Project/Debugger/cosc.exe");
std::cout << pFileName << std::endl;
return 0;
}
Steve
|
|
|
|
|
i get this error :
error C2664: 'new_array' : cannot convert parameter 3 from 'double (*)[10][2]' to 'double *[][2]'
do i type the Array wrong ?
<code>
code:
void find_values( long p[] ,int nCount ,double *pmid , double *ps);
void new_array(long p[] , int nCount , double *dp[][2]);
void print_array2( double p[][2] , int fCount);
int main()
{
double dp[N][2];
new_array(pinakas ,N ,&dp);
print_array2( dp , N);
}
void find_values(long p[] ,int nCount , double *pmid , double *ps)
{
double mid , s;
mid =0;
s = 0;
for ( int i =0 ; i < nCount ; i++ )
{
mid = mid + p[i];
}
mid = (mid/nCount);
for (int z = 0 ; z < nCount ; z++)
{
s = s + (p[z] - mid)*(p[z] -mid);
}
s = pow((s/(nCount -1)) , (1/2));
*pmid = mid;
*ps = s;
}
void new_array(long p[] , int nCount , double *dp[][2])
{
double min , s;
find_values( p,nCount ,&min , &s);
for (int i = 0 ; i < nCount ; i++)
{
*dp[i][1] = p[i];
if ( p[i] > min )
{
if ( p[i]*0.85 > min)
{
*dp[i][2] = p[i]*0.85 ;
}
else
{
*dp[i][2] = p[i];
}
}
else
{
if (p[i]*1.15 <min)
{
*dp[i][2] = p[i]*1.15;
}
else
{
*dp[i][2] = p[i];
}
}
}
} </code>
-- modified at 5:48 Sunday 20th May, 2007
|
|
|
|
|
how i put my code in the site like quote ? (so it can take the tabs that has in Visual studio Eviroment)
if( x == y )
{
y = x ;//used spaces
}
and not
if ( x ==y)
{
y=x;
}
or you only can do it with hiting space many times
|
|
|
|
|
Immunity18 wrote: how i put my code in the site like quote ? (so it can take the tabs that has in Visual studio Eviroment)
check the "Ignore HTML tags in this message (good for code snippets)" checkbox before submitting code snippets.
|
|
|
|
|
/*
This is probably unrelated to your error, but you have a syntax
error in your code snippet. See below...
*/
void new_array(long p[] , int nCount , double *dp[][2])
{
double min , s;
find_values( p,nCount ,&min , &s);
for (int i = 0 ; i < nCount ; i++) {
*dp[i][1] = p[i];
if ( p[i] > min ) {
if ( p[i]*0.85 > min) {
*dp[i][2] = p[i]*0.85 ;
} else {
*dp[i][2] = p[i];
}
} else {
// ****************************************
// *** Your missing a parenthesis below ***
// ****************************************
if (p[i]*1.15 {
*dp[i][2] = p[i]*1.15;
} else {
*dp[i][2] = p[i];
}
}
}
}
|
|
|
|
|
It was html fault ( < min ) took it as a Html tag :/
i think my fault is on writing the name of array
|
|
|
|
|
bob16972 wrote: ****************************************
// *** Your missing a parenthesis below ***
// ****************************************
if (p[i]*1.15 {
Which is actually:
if (p[i]*1.15 <min) {
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
Hi i would like to inform me anyone (or give me link) about data types
int float double long
like : int = 1,2,3,4,5 natural numbers
float = [0,1) ? 0.054353234243 0.9999999999999999 0.000000 but not 1 ?
double is ?
long is ?( bigger than int ? but still natural numbers?)
how i put them in printf("%", )? printf("%d %s " ,int , str) these 2 i know
ALso what about casting ? int x = (int) (while this is double)
i can combine a float + int to become a double ?
-- modified at 17:30 Saturday 19th May, 2007
|
|
|
|
|
Well int are not natural numbers: they are signed and bounded (i.e. there is a max int and a min int).
float are floating point numbers , i.e. you can think about them as real numbers, but, in fact they are somewhat different (being composed by sign , maintissa , exponent , they are bounded and have variable precision...
BTW what do you think about a good book on C language programming?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
dont know suggest me one . University gave meh 3 C & C++ language programming books but i think their build sux :/ i learnt more things via codeproject and google than from the book :P (well maybe i am a bit lazy to search 900 pages) but i do searching them and still dont find anything to understand the Data types
about int yes they can be negative too !:P
Deitel & Deitel C language programming is he one
|
|
|
|
|
Well,
Kernighan & Ritchie [^] is must.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
Immunity18 wrote: University gave meh 3 C & C++ language programming books but i think their build sux :/ i learnt more things via codeproject and google than from the book (well maybe i am a bit lazy to search 900 pages) but i do searching them and still dont find anything to understand the Data types
Well, should such a topic have been included in the books? Just because a book does not contain exactly what you happen to be looking for at the moment does not necessarily make it the book's fault. It just may be that data types were not in the book's scope.
Immunity18 wrote: about int yes they can be negative too !:P
Which is why an int cannot be a natural number.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
also about long and double ? and how i put them inside strings ?
printf("%lf",double) ? i do this and it print me 0.00000 :/
|
|
|
|
|
Have a look at this [^].
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
double thanks brb from amazon.com !
|
|
|
|
|
Immunity18 wrote: printf("%lf",double) ? i do this and it print me 0.00000 :/
What should it print? What is the value of double ?
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
|
|
|
|
|
a fault in my code :P now it prints the right values !
thank for the intresting
|
|
|
|
|
I dont know how to create a fuction that return 2 values and how i give these values in 2 varablies in (int main() )
i found on google something but i think its for C#
I am working on C
#include <stdio.h>
#define N 10
#include <stdlib.h>
#include <math.h>
void insert_array ( int p[] , int nCount , int a , int b);
(double , double) find_values( int p[] ,int nCount );
void print_array1( int p[] , int nCount);
void print_array2( long p[][2] , int fCount);
int main()
{
int pinakas[N];
double mid , s ;
(mid , s) = find_values(pinakas , N);
printf ("%lf %lf",s ,mid);
return 0;
}
(double ,double) find_values(int p[] ,int nCount )
{
double mid ;
double s ;
for ( int i =0 ; i < nCount ; i++ )
{
mid = mid + p[i];
}
mid = mid/nCount;
for (int z = 0 ; z < nCount ; z++)
{
s = s + (p[z] - mid)*(p[z] -mid);
}
s = pow((s/(nCount -1)) , (1/2));
return (mid , s);
}
|
|
|
|
|
I'm no C++ expert, but won't it be easier to send references of the variables?
void find_values(int p[] ,int nCount, double *mid, double*s )
--Star
|
|
|
|
|
well not because you dont know mid and s .
fuction find_values will find the mid and s (and return them)
but i dont know what reference is about !
|
|
|
|
|
When we reference a variable we send its address(i.e. original variable not a copy), while in usual function calling, you send a copy of the variable.
In other words, any changes made to a variable, will remain in the function. But if you sent a reference, any changes to that reference of the variable will return to main.
Hope that explains it a little.
Well there is another way, you can create a global array of type double that holds two elements, knowing that you will assign mid and s as the first and second elements respectively. When you call the function it will access the array, and you can add the values of mid and s. Later you can access them in main.
Or if you know about referencing a little, you can create an array inside main, and send its reference -the address- and you can assign its values inside the function. The function will return void, but because you sent the array's reference (not a copy) you will assign the values of mid and s.
Hope it's clear.
--Star
|
|
|
|
|
Well, from the logical (i.e. language independent) standpoint, functions can get three categories of arguments:
(1) The IN arguments, i.e. values set by the caller and used inside the function. This category is the most used one.
(2) The OUT arguments, i.e. values set by the function and returned to the caller.
(3) The INOUT arguments, i.e. values set by the caller and returned (usually modified) by the function.
Of course, you need two arguments of the second category (OUT ).
In C language every argument is passed by value, hence you can implement OUT arguments only by means of pointers (as already suggested by Star08):
void find_values(int p[] ,int nCount, double * pmid, double *ps);
int main()
{
int pinakas[N];
double mid , s ;
find_values(pinakas , N, &mid, &s);
printf ("%lf %lf",s ,mid);
return 0;
}
Of course you need to know a bit of pointers usage.
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler.
-- Alfonso the Wise, 13th Century King of Castile.
|
|
|
|
|
hehe i see ! thx for help !
|
|
|
|
|
my problem is that exercise says : create a fuction find_values (bla bla bla) that takes as input (1) Array's name (2) Array's Size and as OUTput (1) mid (2) s
mid = x1+x2+x3...+xn /n
s2 =... :P difficult to right it in text
is there a way to not use pointers? or if its nessesary can u tell me how i have to write the void find_array { } fuction ?
|
|
|
|
|