[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

how to do this?

questions

10/16/2008 3:03:00 AM

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;}
17 Answers

Ian Collins

10/16/2008 3:40:00 AM

0

questions wrote:
> 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.

--
Ian Collins

Jerry

10/16/2008 6:28:00 AM

0

On Oct 16, 11:03 am, questions <mengqidhu...@yahoo.cn> wrote:
> 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.

Maxim Yegorushkin

10/16/2008 11:20:00 AM

0

On Oct 16, 4:03 am, questions <mengqidhu...@yahoo.cn> wrote:
> 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/introdu...
http://www.boost.org/doc/libs/1_35_0/libs/spirit/doc/semantic_ac...
(fully working calculator example)

--
Max

Michael

10/16/2008 1:14:00 PM

0

questions wrote:
> 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);

Juha Nieminen

10/16/2008 1:48:00 PM

0

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

Exactly what is the purpose of that scanf?

Jeff Schwab

10/16/2008 6:22:00 PM

0

Ian Collins wrote:
> questions wrote:
>> 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.

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?

Ian Collins

10/16/2008 6:53:00 PM

0

Jeff Schwab wrote:
> Ian Collins wrote:
>> questions wrote:
>>> 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.
>
> 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.

--
Ian Collins

Jeff Schwab

10/16/2008 8:11:00 PM

0

Ian Collins wrote:
> Jeff Schwab wrote:
>> Ian Collins wrote:
>>> questions wrote:
>>>> 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.
>> 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.

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 agree that the OP's code is really C, but apparently for completely
different reasons.

Ian Collins

10/16/2008 8:15:00 PM

0

Jeff Schwab wrote:
> Ian Collins wrote:
>> Jeff Schwab wrote:
>>> Ian Collins wrote:
>>>> questions wrote:
>>>>> 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.
>>> 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.
>
> 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.

--
Ian Collins

Jeff Schwab

10/16/2008 9:20:00 PM

0

Ian Collins wrote:
> Jeff Schwab wrote:
>> Ian Collins wrote:
>>> Jeff Schwab wrote:
>>>> Ian Collins wrote:
>>>>> questions wrote:
>>>>>> 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.
>>>> 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.
>> 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.

Fair enough; I didn't mean to sound critical. Just trying to understand
a POV that was new to me.