You pros are once newbies like us. Hoped you might take a little time sharing your expertise. Got freaked out when our teacher gave us this activity, where she haven't taught this to us yet. So this is the activity (LOOPING) :

Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.

OUTPUT must be:

n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0

if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0

Here my code, it's so easy :) :)

#include <iostream>

int main(){
    int n;
    while(1){
        system("cls");
        std::cout << "Enter n: ";
        std::cin >> n;
        std::cout << std::endl;
        int i = 0;
        while(i <= n){
            int j = i;
            while(j >= 0){
                std::cout << j << (j == 0? " ":"==");   
                j--;
            }
            i++;
            std::cout << std::endl;
        }
        while(1){
            std::cout << "n Continue?(Y/N): ";
            char choose;
            std::cin >> choose;
            if (choose == 'Y' || choose == 'y') break;
            else if (choose == 'N' || choose == 'n') return 1;
            else std::cout << "n You mean? Y or N: ";
        }
    }
}

@sinz : That was a great help dude. Thanks a lot. :))

@Sinz_1 : Did you read the rules?
You may provide homework help, not give the whole solution!
Besides try to use the Code option above a post to give a decent format if you post any code in the future.
You seem to be a nice guy/girl, so I will not downvote you.
Happpy computing! :)

@exoruel: if you want to improve yours, write your own code when you understand the method.
@ddanbe: Ok guy, no more next time :D :D, and i tried to use code option but it didn't work for me, let me know some guide to do it? Thanks xD xD

Member Avatar for iamthwee

To be honest I didn't find anything wrong in the way sinz_1 formatted their code, it reads OK to me, perhaps I would have used a few more curly brackets around the if else statement to aid clarity and dropped the ternary operator as it tends to confuze newbies but this is just nitpicking.

That being said nothing is achieved by posting complete solutions. I've noticed lots of homework questions tend to be based around nesting loops as I guess this is an important concept to get when you're programming... Unfortunately, the only way to get this is by trial and error, attempting to write this yourself.

Although you'll get a 'free lunch' by copying a complete answer it nothing compared to the learning offered by doing this yourself as down the line, this concept/idea crops up time and time again.

@iamthwee : indeed nothing is wrong with the formatting of the code now, I guess it miraculously changed itself!?! Or should we say:
"Sometimes Daniweb moves in mysterious ways."

Good day guys, sorry for the late reply. Yeah I am a newbie, a newbie who wants to learn and not just to copy everything that has been given or taught unto me. Yeah I get concepts from the code that was given to me by sinz_1 (who where a great guy/lady), but I innovated it and made it my own. I know what you guys wanted to say, and thanks. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.