Author Topic: I need a HELP!!  (Read 6457 times)

0 Members and 1 Guest are viewing this topic.

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
I need a HELP!!
« on: August 24, 2011, 01:12:39 pm »
A program that produces a sequence number (in alternate arrangement or in reverse order) using for loop, while loop, and do while loop statements.


example output:
5,1,4,2,3,3,2,4,1,5


Kindly help me with this please!
I'm having a self study here...

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: I need a HELP!!
« Reply #1 on: August 24, 2011, 01:39:05 pm »
In C:
Code: [Select]
#include <stdio.h>
int main()
{
    int max=5, i;
    for(i=0; i<max; i++) printf("%i, %i,", max-i, i+1);
    return 0;
}

Not tested it, no compiler available, but I think it should work...

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #2 on: September 01, 2011, 11:49:21 am »
thank you for that but maybe there some mistake because only X1 shows in the prompt without stopping... can u fix that problem?? PLEASE!!!

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: I need a HELP!!
« Reply #3 on: September 01, 2011, 12:24:27 pm »
No mistake. You asked for an algorythm to generate that input, and it does it right. Execute it from a shell and see it.

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #4 on: September 01, 2011, 10:48:53 pm »


#include <iostream.h>
int main()
{
   int max=2, i;
   for(i=0; i<max; i++)
      cout<<"5,1,4,2,3 ", max-i, i+1;
   return 0;
}
Thank you sir, your code is great help for me.


The output that is 5,1,4,2,3,5,1,4,2,3


How can I make that output  in this form: 5,1,4,2,3,3,2,4,1,5

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: I need a HELP!!
« Reply #5 on: September 01, 2011, 11:16:49 pm »
What do you want to do with that code? What you asked for in the first post has been answered.

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #6 on: September 01, 2011, 11:45:35 pm »
I just want to know if my code is correct.

Offline ca0s

  • VIP
  • Sir
  • *
  • Posts: 432
  • Cookies: 53
    • View Profile
    • ka0labs #
Re: I need a HELP!!
« Reply #7 on: September 02, 2011, 01:37:08 am »
Don't know C++ but

Code: [Select]
#include <iostream.h>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      cout<<max-i, ",",  i+1, ",";
   return 0;
}
I think is what you want.

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: I need a HELP!!
« Reply #8 on: September 02, 2011, 05:53:45 am »
Code: [Select]
#include <iostream>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      std::cout << (max-i) << "," << (i+1) << ",";
   return 0;
}

<iostream>, drop .h.. C++ also needs to know what "cout" is. and "," won't work as you think in this situation, you need <<. needless to say printf is alot less ugly.

OP you seem to be stuck between 2 languages, pick one. I'd recommend C. Also you've been working on this for more than a week, seriously google how to code. ca0s gave you algo, the only thing left for you to do is implement it in your language.


Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #9 on: September 02, 2011, 06:01:34 am »
There's missing sir.
The output of your code is 54321
The output should be like this 5,4,3,2,1,1,2,3,4,5
Can your show me how? please!

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: I need a HELP!!
« Reply #10 on: September 02, 2011, 06:07:25 am »
There's missing sir.
The output of your code is 54321
The output should be like this 5,4,3,2,1,1,2,3,4,5
Can your show me how? please!

I believe you are mistaken sir. Don't change it though(all these quotes are you):

Quote
The output should be like this 5,4,3,2,1,1,2,3,4,5
Quote
How can I make that output  in this form: 5,1,4,2,3,3,2,4,1,5
Quote
example output:
5,1,4,2,3,3,2,4,1,5

The code matches #2 & #3, and yeah it works.


Code: [Select]
PS K:\>cat test.cpp
#include <iostream>
int main()
{
   int max=5, i;
   for(i=0; i<max; i++)
      std::cout << (max-i) << "," << (i+1) << ",";
   return 0;
}
PS K:\>g++ -o test test.cpp
PS K:\>./test; "`n"
5,1,4,2,3,3,2,4,1,5,

PS K:\>

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #11 on: September 02, 2011, 06:32:39 am »
It's ok now sir. Thank you so much!!!
Can you be my teacher? If you don't mind. Because I want to know more about C++ programming.

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: I need a HELP!!
« Reply #12 on: September 02, 2011, 06:35:07 am »
It's ok now sir. Thank you so much!!!
Can you be my teacher? If you don't mind. Because I want to know more about C++ programming.

No. Although a simple google search will bring up hundreds of c++ tutorials... Pick one.

Offline kriminal

  • /dev/null
  • *
  • Posts: 11
  • Cookies: 0
    • View Profile
Re: I need a HELP!!
« Reply #13 on: September 02, 2011, 06:50:22 am »
Okay! Thank you so much for the help.
Can I ask your help again when I have problems regarding C++ programming?

Offline xzid

  • Knight
  • **
  • Posts: 329
  • Cookies: 41
    • View Profile
Re: I need a HELP!!
« Reply #14 on: September 02, 2011, 07:00:52 am »
Just post a thread, I'm sure someone will help. Don't go overboard with it though, you need to put alot of effort into getting it to work before asking others for help.

edit: I should also point out that I, like ca0s, am a C programmer not C++.
« Last Edit: September 02, 2011, 07:03:20 am by xzid »