Thread View: att.lang.c++
3 messages
3 total messages
Started by CM
Sun, 29 Sep 2002 17:03
New CSCI Student needing help!!
Author: CM
Date: Sun, 29 Sep 2002 17:03
Date: Sun, 29 Sep 2002 17:03
34 lines
2427 bytes
2427 bytes
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;
}
--
CM
Re: New CSCI Student needing help!!
Author: Edwin Brozowski
Date: Sun, 29 Sep 2002 18:35
Date: Sun, 29 Sep 2002 18:35
25 lines
1814 bytes
1814 bytes
Out-classed by a High Schooler!!!!
This is in prestandard C++, but you get the idea on how to do it. This
works! I have compiled and executed it my self in Microsoft Visual Studio!
#include <iostream.h>
int main()
{
int a;
int counter=0;
int b;
int total=0;
cout<<"This program will multiply two integers(This number can be
negative!):"<<endl;
cout<<"Please enter first number:"<<endl;
cin>>a;
cout<<"Please enter second number(This number cannot be negative!):"<<endl;
cin>>b;
do
{
total=total+a;
counter++;
}while(counter<b);
cout<<total<<endl;
return 0;
}
Re: New CSCI Student needing help!!
Author: 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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads