Article View: att.lang.c++
Article #111Re: New CSCI Student needing help!!
From: Mike Wahler
Date: Sun, 29 Sep 2002 18:48
Date: Sun, 29 Sep 2002 18:48
61 lines
2570 bytes
2570 bytes
CM <mckenzie992@comcast.net> wrote in message
news:EnGl9.19402$q42.1001817@bin3.nnrp.aus1.giganews.com...
> Hello all,
> I have what I am sure most of you will find an extremely easy program to
> write. It is to simply multiply two numbers together without using '*'
So,
> two numbers, X times Y - X+X+X .. Y times. I imagine a for loop is needed
> but I can not figure out how to write it and - also have searched for a
few
> hours for clues on how to. Below is what I have so far, don't laugh, I
have
> to start somewhere!! But nonetheless, I have to get rid of the expression
> c=a*b and get a loop in there ... Can anyone help me?
>
>
> #include <iostream>
> using namespace std;
> int main()
>
> {
> double a;
> double c;
> double b;
> cout << "This program will multiply two integers:" <<endl;
> cout << "Please enter first number:" <<endl;
> cin >> a;
> cout << "Please enter second number:"<<endl;
> cin >> b;
>
> c=a*b;
>
>
> cout <<"The answer is " << c <<endl;
>
>
>
> }
It would have been better for you to at least
try to write the loop and post it here, no matter
how 'wrong' you might believe it is.
Here's one of several possiblities.
(Don't just turn it in, though, be prepared
to explain to your instructor *why* it works. :-) )
int mult(int a, int b)
{
int result(0);
while(a--)
result += b;
return result;
}
Any questions, just ask.
HTH,
-Mike
Technical Details
Message-ID:
<an7hlg$5ip$1@slb1.atl.mindspring.net>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mailReferences:
<EnGl9.19402$q42.1001817@bin3.nnrp.aus1.giganews.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,d133c4fb76037b3e X-Google-Attributes: gid109fba,public X-Google-Thread: 10d4ba,d133c4fb76037b3e X-Google-Attributes: gid10d4ba,public X-Google-ArrivalTime: 2002-09-29 11:44:01 PST Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!nntp-relay.ihug.net!ihug.co.nz!west.cox.net!cox.net!newsfeed1.earthlink.net!newsfeed.earthlink.net!stamper.news.pas.earthlink.net!stamper.news.atl.earthlink.net!harp.news.atl.earthlink.net!not-for-mail From: "Mike Wahler" <mkwahler@ix.netcom.com> Newsgroups: att.lang.c++,comp.lang.c++ Subject: Re: New CSCI Student needing help!! Date: Sun, 29 Sep 2002 11:48:07 -0700 Organization: MindSpring Enterprises Lines: 63 Message-ID: <an7hlg$5ip$1@slb1.atl.mindspring.net> References: <EnGl9.19402$q42.1001817@bin3.nnrp.aus1.giganews.com> NNTP-Posting-Host: 3f.32.60.5e X-Server-Date: 29 Sep 2002 18:44:00 GMT X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200