10 Replies - 676 Views - Last Post: 03 September 2008 - 06:23 AM Rate Topic: -----

#1 krain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 19-July 08

i need help in my assignment.

Post icon  Posted 03 September 2008 - 04:07 AM

Sir, ma'am.

i need help..in c++..arra,,


anyone can help me to solve my problem i am new about c++ programing,,

i have assignment about array,,

i need to create a program array in parameter,

the output that pop when i run a program is:

12345
1234
123
12
1

sorry for wrong grammar,

passing of program tomorrow morning..
please help me to my homework..

sincerely your fellow,
krain

Is This A Good Question/Topic? 0
  • +

Replies To: i need help in my assignment.

#2 red_4900  Icon User is offline

  • Code T(h)inkers
  • member icon

Reputation: 21
  • View blog
  • Posts: 1,119
  • Joined: 22-February 08

Re: i need help in my assignment.

Posted 03 September 2008 - 04:45 AM

your question's a bit unclear. what do you want your code to do? and what did your code do? and please post the code of what you've done so far. then we'll help you :)
Was This Post Helpful? 0
  • +
  • -

#3 krain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 19-July 08

Re: i need help in my assignment.

Posted 03 September 2008 - 05:57 AM

View Postred_4900, on 3 Sep, 2008 - 04:45 AM, said:

your question's a bit unclear. what do you want your code to do? and what did your code do? and please post the code of what you've done so far. then we'll help you :)


my teacher gave me an assignment related to my last topic that is array,
my teacher give a problem that the output is
12345
1234
123
12
1

but i can't do,

this is my code,,

#include<iostream.h>
main()
{


for (int i = 6; i > 1; i = i--){
	for(int n = 1; n < i; n++){
	

	cout<<""<<n;
	}
	}
	cout<<"\n";
	return 0;
}
	


sorry,, i am new in the world of programming

please..

MOD EDIT: Please :code:
Thanks, gabehabe :)
Was This Post Helpful? 0
  • +
  • -

#4 sensui  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 146
  • Joined: 24-August 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:03 AM

Try this code, it should work:
#include <iostream.h>

int main() {
  int i, n;
  n = 5;
  while( n > 0 ) {
    for( i = 1; i <= n; i++ ) cout << i;
    cout << endl;
    n--;
  }

  cin.get();
  return EXIT_SUCCESS;
}



Was this post helpful ? :) -->
Was This Post Helpful? 1
  • +
  • -

#5 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:05 AM

EDIT: Dammit sensui, you beat me to it~ Then again, why use a while loop when you only want to execute a set number of times? It makes more sense to use nested for loops :P

OK, since you've shown an effort, I don't mind helping you out.

Here's some very short code which will achieve what you want to do.

#include <iostream>
using namespace std;

int main ()
{
    for (int i = 5; i > 0; i--)
    {
        for (int j = 1; j <= i; j++)
            cout << j;
        cout << endl;
    }
    cin.get ();
    return EXIT_SUCCESS;
}



Was this helpful? :wink:
Was This Post Helpful? 1
  • +
  • -

#6 krain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 19-July 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:07 AM

View Postsensui, on 3 Sep, 2008 - 06:03 AM, said:

Try this code, it should work:
#include <iostream.h>

int main() {
  int i, n;
  n = 5;
  while( n > 0 ) {
    for( i = 1; i <= n; i++ ) cout << i;
    cout << endl;
    n--;
  }

  cin.get();
  return EXIT_SUCCESS;
}



Was this post helpful ? :) -->



yup,,your code is helpful..thanks for the help,,

*_*..

your the one!!.
thanks again.
Was This Post Helpful? 0
  • +
  • -

#7 gabehabe  Icon User is offline

  • GabehabeSwamp
  • member icon




Reputation: 1377
  • View blog
  • Posts: 10,951
  • Joined: 06-February 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:10 AM

Hey, read my edit. :P

A while loop works, but it seems a little pointless to use one when you only want to execute a loop a set number of times.

I've had this discussion so many times~
Oh well.

A while loop is designed for a sentinel value. Often something along the lines of: while (!exit) since we do not know how many times it will be executed.

The same can be applied to a for loop. Both can be used for the same purpose, but they are designed for a specific purpose. :)
Was This Post Helpful? 1
  • +
  • -

#8 sensui  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 146
  • Joined: 24-August 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:13 AM

@gabehabe:
you are right but I use the while loop just for simplicity
Was This Post Helpful? 0
  • +
  • -

#9 krain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 19-July 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:13 AM

View Postkrain, on 3 Sep, 2008 - 06:07 AM, said:

View Postsensui, on 3 Sep, 2008 - 06:03 AM, said:

Try this code, it should work:
#include <iostream.h>

int main() {
  int i, n;
  n = 5;
  while( n > 0 ) {
    for( i = 1; i <= n; i++ ) cout << i;
    cout << endl;
    n--;
  }

  cin.get();
  return EXIT_SUCCESS;
}



Was this post helpful ? :) -->



yup,,your code is helpful..thanks for the help,,

*_*..

your the one!!.
thanks again.



another question. sorry if i have many question, or favor.

what thus the cin.get();
stuns for?
and what its function?

please..
Was This Post Helpful? 0
  • +
  • -

#10 sensui  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 30
  • View blog
  • Posts: 146
  • Joined: 24-August 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:15 AM

If you want to see the output of your program you must use cin.get(). It just waits for you to press enter.
Was This Post Helpful? 0
  • +
  • -

#11 krain  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 30
  • Joined: 19-July 08

Re: i need help in my assignment.

Posted 03 September 2008 - 06:23 AM

View Postgabehabe, on 3 Sep, 2008 - 06:05 AM, said:

EDIT: Dammit sensui, you beat me to it~ Then again, why use a while loop when you only want to execute a set number of times? It makes more sense to use nested for loops :P

OK, since you've shown an effort, I don't mind helping you out.

Here's some very short code which will achieve what you want to do.

#include <iostream>
using namespace std;

int main ()
{
    for (int i = 5; i > 0; i--)
    {
        for (int j = 1; j <= i; j++)
            cout << j;
        cout << endl;
    }
    cin.get ();
    return EXIT_SUCCESS;
}



Was this helpful? :wink:


thank you for the code,,

but what is cin.get(); stuns for and its function..

please..


View Postsensui, on 3 Sep, 2008 - 06:15 AM, said:

If you want to see the output of your program you must use cin.get(). It just waits for you to press enter.



thanks for the info you shared with me..
thanks,,
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1