//flex table opened by JP

Click to See Complete Forum and Search --> : C++ Question


jmak
05-11-2004, 05:37 PM
Hey! I'm new to the board and I have a question about C++. I'm pretty new to the language, so please bare with me.

I have to write a program, but I have no idea how to start it. My teacher doesn't want to help us because we have to figure it out, but it's something we've never learned. So I'm asking for some help. Perhaps if it was started out I could figure out the rest or just see how to do it.

Write a program that finds the smallest of several integers. The program will first ask the user to enter the numbers of integers to be entered; second it will read the numbers from the keyboard and finally it will find and display the smallest of them.

I get that there will be for loop involved and probably the if statement. What I don't get is how to use the functions where you ask the user to enter numbers when you don't know the exact number. (Because if you did, then you would know how many times to include a variable after cin)

Thanks!

nothing
05-11-2004, 09:51 PM
Hey, welcome to SysOpt!

Now answering your question, you could do something like this:

#include <iostream>

int main()
{
int number = 0;

while(number != -1){
std::cout << "Enter a number, -1 to quit: ";
std::cin >> number;

// do what you got to do here
}

return 0;
}


As for the "do what you got to do here" part, assume that the first number entered is the smallest and start testing the other numbers from there. Hope that helps ;)

WillihamS
05-12-2004, 08:19 AM
There's a realy good web page called www.cplusplus.com that has a complete beginers guide to C++ its just realy long.:cool:

jmak
05-12-2004, 01:55 PM
Thanks guys!

Ok I have another question. I started this program:



#include <iostream.h>
void main ()

{ int i, n;
for(i=1; i<=10; i++)
{
for (n=1; n<=i; n++)
cout << '*';
cout << endl; }

cout << endl;

for(i=1; i<=10; i++)
{
for (n=10; n>=i; n--)
cout << '*';
cout << endl; }


Now I'm not sure how to find the reflection of the two.

Thanks again.

nothing
05-12-2004, 04:28 PM
What do you mean? :confused:

jmak
05-12-2004, 10:38 PM
From the two codes I posted it looks like this:

*
**
***
****
*****
******
*******
********
*********
**********

and

**********
*********
*******
******
*****
****
***
**
*

I'm supposed to write a program that will find the reflection of the two. That is the straight line of * going down would be on the right side. Do you know what I mean?

nothing
05-13-2004, 06:31 AM
*
*
*
*
*
*
*
*
*
*

*
*
*
*
*
*
*
*
*
*

Is this how it is supposed to look?

jmak
05-13-2004, 05:57 PM
Not quite. I got someone to scan the problem. Here's what it would look like:

http://www.members.aol.com/neighbormoby/c.jpg

The first part is I have to just display the patterns underneath each other and after that use nested for loop to display them side by side. A and B I got, but not C and D.

nothing
05-13-2004, 09:46 PM
Hey, I know that problem! Is it from the book C++ How to Program fourth edition? I will solve it again and post the code as soon as possible.

fishybawb
05-14-2004, 06:59 AM
Reminds me of your old thread nothing ;)

http://www.sysopt.com/forum/showthread.php?s=&threadid=149720

jmak
05-14-2004, 06:53 PM
Thanks fishybawb for the link. I already got the first two, it's the darn third and fourth one I can't figure out. I'm not sure what book it's from. We don't have textbooks. LOL. We just run from the teacher's sometimes insane mind. :)

nothing
05-14-2004, 09:39 PM
Originally posted by nothing
Hey, I know that problem! Is it from the book C++ How to Program fourth edition? I will solve it again and post the code as soon as possible.

Do you always remember everything? :D