pls help modify it

J

james

Hi,all
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).
Thanks in advance!

#include <windows.h>
#include <iostream.h>
#include <cstdlib>
int a,b,c,d;
int m,n;

DWORD WINAPI ThreadFunc1(HANDLE Thread1) //define thread1
{
m=a+b+c+d;
return 0;
}

DWORD WINAPI ThreadFunc2(HANDLE Thread2) //define thread2
{
n=a*b*c*d;
return 0;
}

int main() //main function
{
HANDLE Thread1;
HANDLE Thread2;

DWORD dwThreadId1;
DWORD dwThreadId2;

int a,b,c,d;
int m,n;

cout<<"please input a,b,c,d:"<<endl;
cin>>a>>b>>c>>d;


Thread1=::CreateThread //create thread1
(NULL,0,ThreadFunc1,NULL,0,&dwThreadId1);
Thread2=::CreateThread //create thread2 (NULL,
0,ThreadFunc2,NULL,0,&dwThreadId2);

::WaitForSingleObject(Thread1,INFINITE);
::CloseHandle(Thread1);
::WaitForSingleObject(Thread2,INFINITE);
::CloseHandle(Thread2);

cout<<"m="<<m<<endl;
cout<<"n="<<n<<endl;

system ("pause");
return 0;
}
 
C

Chris Dollin

james said:
Hi,all
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).
Thanks in advance!

#include <windows.h>
#include <iostream.h>
#include <cstdlib>
int a,b,c,d;
int m,n;

(etc)

I suggest asking for help on a Windows-specific C++ program in a group
that discusses at least one of Windows and C++.

When you do that, saying what input you /tried/ and what output
you /got/ would be helpful to your readers.
 
G

Guest

    Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).
    Thanks in advance!

#include <windows.h>

this is a non-standard header
#include <iostream.h>

this is a non-standard header (to *both* C and C++)
#include <cstdlib>

this is a non-standard header (in C)
int a,b,c,d;
int m,n;

DWORD WINAPI ThreadFunc1(HANDLE Thread1)     //define thread1

threading is not supported by C (or C++).
Please post this to a Microsoft specific group.
You may want to make sure its a C++ group as well

<snip>
 
C

CBFalconer

james said:
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how
can I modify it and get the result that I want? (input a,b,c,d
and get m=a+b+c+d , n=a*b*c*d).

#include <windows.h>
#include <iostream.h>
#include <cstdlib>

You are obviously using C++. This is comp.lang.c. I suspect you
will get better answers on comp.lang.c++. The question is
off-topic here.
 
M

Martin Ambuhl

james said:
Hi,all
Today i've met with a big problem. After compling the following
document, I entered 4 integers but cannot get what I want. how can I
modify it and get the result that I want? (input a,b,c,d and get m=a+b
+c+d , n=a*b*c*d).

/* We start by removing the stuff that is defined in neither C nor C++,
* which includes at least <windows.h>, DWORD, WINAPI, HANDLE.
* Then we remove all the crap that is not C.
* That includes the undeclared identifiers cout, cin, endl
* the syntax errors
* like ::CreateThread, and the absurd use of a string literal
* as the RHS operand for the left shift operator.
* The absurd comments that only repeat the code should go as well.
* The shadow declarations are silly as well.
* Let's see what we might have for a program then.
* */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int a, b, c, d;

printf("Please input the integers a, b, c, and d,\n"
" separated by whitespace (and nothing else): ");
fflush(stdout);
if (4 != scanf("%d %d %d %d", &a, &b, &c, &d)) {
printf("If you can't follow simple directions,\n"
"I'm not going to play.\n");
exit(EXIT_FAILURE);
}

printf("You entered %d %d %d %d\n"
"The sum is %d and the product is %d\n",
a, b, c, d, a + b + c + d, a * b * c * d);
return 0;
}
 
J

james

(etc)

I suggest asking for help on a Windows-specific C++ program in a group
that discusses at least one of Windows and C++.

When you do that, saying what input you /tried/ and what output
you /got/ would be helpful to your readers.

--
"It's a hat as long as I /say/ it's a hat."         Jane, /A College of Magics/

Hewlett-Packard Limited registered office:                Cain Road, Bracknell,
registered no: 690597 England                                    Berks RG12 1HN

Thank you so much. I'm a newbie here. I'm deeply moved that so many
people gave me the answer!
 
J

james

You are obviously using C++.  This is comp.lang.c.  I suspect you
will get better answers on comp.lang.c++.  The question is
off-topic here.

Yeah, as they have said, I've made a big mistake as I'm a newbie
here.Sorry!
 
J

james

/* We start by removing the stuff that is defined in neither C nor C++,
  * which includes at least <windows.h>, DWORD, WINAPI, HANDLE.
  * Then we remove all the crap that is not C.
  * That includes the undeclared identifiers cout, cin, endl
  * the syntax errors
  * like ::CreateThread, and the absurd use of a string literal
  * as the RHS operand for the left shift operator.
  * The absurd comments that only repeat the code should go as well.
  * The shadow declarations are silly as well.
  * Let's see what we might have for a program then.
  * */

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
     int a, b, c, d;

     printf("Please input the integers a, b, c, and d,\n"
            " separated by whitespace (and nothing else): ");
     fflush(stdout);
     if (4 != scanf("%d %d %d %d", &a, &b, &c, &d)) {
         printf("If you can't follow simple directions,\n"
                "I'm not going to play.\n");
         exit(EXIT_FAILURE);
     }

     printf("You entered %d %d %d %d\n"
            "The sum is %d and the product is %d\n",
            a, b, c, d, a + b + c + d, a * b * c * d);
     return 0;



}- Hide quoted text -

- Show quoted text -

Really sorry for disturbing you all.And thank you all the same.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
ScottChare

Latest Threads

Top