My first program :D


*EDIT* okay. I feel stupid. Sorry. Just looking through my post, realized that the problem is probably in "loopcounter++", being directly after the second loop. Sorry, I should have checked through that better D: *EDIT*
Well shit. I was almost done typing my post, when I clicked outside of the text box and hit "backspace" by accident. :/

Anyways :D I'll start by saying that I am new to C++, and to coding, for the most part. I'm 15, and I've been intrigued by computers since I was 4. I've been using them avidly (or unhealthily) since then. I began writing simple "Qbasic" programs when I was 6. started taking apart computers when I was 7. (I actually just started getting paid for that, as I now have a job as a tech at a computer store, building custom PCs.

Anyways, I'm really interested in programming. Just the thought of being able to have complete control over a machine, or a program with just text is mind boggling to me. It's truly an amazing thing.

So, I decided to pick up a language. I chose C++ because it seems like a very "Trial and error" sort of language. I like problem solving :D

Okay, so. Now that my story's out of the way, I can explain my predicament :) This morning, I started on my first program. Not my first first program, as that was Hello World.

No, this is my first independent program, my first program without the help of a tutorial. My first program actually written by me.

What I was trying to do was get the program to count to 10, 10 times using loops. After every 10, it would show which loop it was on.

1
2
3
4
5
6
7
8
9
10
1
1
2
3
4
5
6
6
7
8
9
10
2
1
2...etc.

Of course, not the most useful program out there, but I thought it might have been a good training exercise.

Here is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
int numbercounter = 0;  //variable counts to 10
int loopcounter = 0;   //Variable counts the loops
int main()
{
    while (loopcounter<10) { //First loop
          while (numbercounter<10){  //second loop
          numbercounter++;   //Plus one to number
          cout<< numbercounter;  //displays number
          cout<< "\n";  //next line
          } //end of second loop
    loopcounter++;  //
    cout<< "  "
    cout<< loopcounter;
    cout<< "\n";
    }
    return 0;
}


I'm stuck :/ I've been working at it for an hour, and I can't get anything out of it D: I don't know what I did wrong, but it simply counts to 10 twice and kicks the bucket. It's probably something stupid that I missed.

I hope I don't sound like some spoiled kid who tries something out and quits the second he fails at it :P

Anyways, I'm sorry for the long introduction, just thought I'd shed a little light on the backstory, as I'm new here. Also, sorry for the stupid problem haha. Hopefully I'll get better at this with practice.

Thanks all :D

-dstrichit

Last edited on
Welcome to the jungle
We got fun 'n' games
We got everything you want
Honey we know the names
We are the people that can find
Whatever you may need
If you got the coding honey
We got your quick-fix


Okay. Now that all the guns, roses, and improper welcomes are out of the way, you appear to have forgotten to #include <iostream> and the using namespace std; at the top of your program, so it shouldn't even compile. If you did remember it and just didn't include it in the snippet... well... never mind.

You need to reset the value of numbercounter before your inner loop runs. This should fix the problem.

Have fun!

-Albatross
Last edited on
Yes, thank you :D Sorry, I should have checked through that more, before posting it. Thanks very much though :D
Now that all the guns, roses, and improper welcomes are out of the way


Let me re-phrase above.

"Now that all the OLD guns, OLD roses, and improper welcomes are out of the way" :)
Not to start a debate but....what's wrong with classic rock? :P
Nothing wrong with classic rock but I still prefer my Metallica, Scorpions, Twisted Sister, Whitesnake, Rainbow, Deep Purple etc etc. Guns, Roses come much later :P
Those are classic :P
Topic archived. No new replies allowed.