how to do this?

Q

questions

I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and next step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

# include <stdio.h>
int main()
{int integer1;
int integer2;
int integer3;
int sum1;
int sum2;

printf("enter the first integer\n");
scanf("%d",&integer1);

printf("enter the second integer\n");
scanf("%d",&integer2);

sum1=integer1 * integer2;
printf ('sum1 is equal to %d\n",sum1);
scanf("%d",&sum1);

printf("enter the third integer\n");
scanf("%d",&integer3);

sum2=sum1*integer3;
printf("the sum2 is %d\n",sum2);

return 0;}
 
I

Ian Collins

questions said:
I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and next step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

# include <stdio.h>

Are you writing C ore C++? Your code is 100% C, so you might be looking
for comp.lang.c.
 
J

Jerry

I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and  next  step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

# include <stdio.h>
int main()
{int integer1;
 int integer2;
 int integer3;
 int sum1;
 int sum2;

 printf("enter the first integer\n");
scanf("%d",&integer1);

 printf("enter the second integer\n");
scanf("%d",&integer2);

sum1=integer1 * integer2;
printf ('sum1 is equal to %d\n",sum1);
//scanf("%d",&sum1); The program could run by just commenting this
line.
printf("enter the third integer\n");
scanf("%d",&integer3);

sum2=sum1*integer3;
printf("the sum2 is %d\n",sum2);

return 0;}

And I think you should ask c++ question here.
 
M

Maxim Yegorushkin

I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and  next  step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

You could use boost::spirit for parsing and calculation.
http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/introduction.html
http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/semantic_actions.html
(fully working calculator example)
 
M

Michael

questions said:
I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and next step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

# include <stdio.h>
int main()
{int integer1;
int integer2;
int integer3;
int sum1;
int sum2;

printf("enter the first integer\n");
scanf("%d",&integer1);

printf("enter the second integer\n");
scanf("%d",&integer2);

sum1=integer1 * integer2;
printf ('sum1 is equal to %d\n",sum1);
scanf("%d",&sum1);

printf("enter the third integer\n");
scanf("%d",&integer3);

sum2=sum1*integer3;
printf("the sum2 is %d\n",sum2);

return 0;}
printf ('sum1 is equal to %d\n",sum1);
This line is wrong, it should be changed into
printf ("sum1 is equal to %d\n",sum1);
 
I

Ian Collins

Jeff said:
Didn't you just make the case that stdio.h was preferable in C++

No. I clearly stated that I preferred the <*.h> for of the C standard
library headers over the <c*> form.
 
I

Ian Collins

Jeff said:
And that you prefer to keep the relevant symbols in the global
namespace, and "would never consider reusing them inside another
namespace." I took that to mean std. So in what way is the OP's code
C, rather than C++? His use of printf rather than iostreams?
I didn't say it wasn't C++. I said it was C just in case the OP had
posted to the wrong group.
 
J

James Kanze

Didn't you just make the case that stdio.h was preferable in
C++, along with use of C library symbols directly in the
global namespace? How do you distinguish "100% C" from C++
written in that style?

No. All he said was that it was preferable to use the C
headers when you wanted a C header. Ian's never said that you
shouldn't use <vector> or <iostream>, rather that T* and printf.
 
L

lemycanh

I want to build a calculation,that is letting the first two integers
multiply,then printf the sum1,and  next  step I input the third
integer,I want to let the third integer multiply the sum1.I' ve done a
program,but it does not run as I want ,how could I rework it?

# include <stdio.h>
int main()
{int integer1;
 int integer2;
 int integer3;
 int sum1;
 int sum2;

 printf("enter the first integer\n");
scanf("%d",&integer1);

 printf("enter the second integer\n");
scanf("%d",&integer2);

sum1=integer1 * integer2;
printf ('sum1 is equal to %d\n",sum1);
scanf("%d",&sum1);

printf("enter the third integer\n");
scanf("%d",&integer3);

sum2=sum1*integer3;
printf("the sum2 is %d\n",sum2);

return 0;}

Why you scanf sum1 agian?
scanf("%d",&sum1);


# include <stdio.h>
# include <conio.h>
int main()
{int integer1;
int integer2;
int integer3;
int sum1;
int sum2;


printf("enter the first integer\n");
scanf("%d",&integer1);


printf("enter the second integer\n");
scanf("%d",&integer2);


sum1=integer1 * integer2;
printf ("sum1 is equal to %d\n",sum1);
/*scanf("%d",&sum1); */


printf("enter the third integer\n");
scanf("%d",&integer3);


sum2=sum1*integer3;
printf("the sum2 is %d\n",sum2);

getch();
return 0;}
 
Q

questions

printf ('sum1 is equal to %d\n",sum1);
This line is wrong, it should be changed into
printf ("sum1 is equal to %d\n",sum1);- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

thanks
 
Q

questions

//scanf("%d",&sum1); The program could run by just commenting this
line.






And I think you should ask c++ question here.- Òþ²Ø±»ÒýÓÃÎÄ×Ö -

- ÏÔʾÒýÓõÄÎÄ×Ö -

thanks so much
 

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
474,169
Messages
2,570,919
Members
47,458
Latest member
Chris#

Latest Threads

Top