How to make characters disappear

For everyone, just starting with C++ or programming at all. Ask newbie questions in this forum!

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

How to make characters disappear

Postby Mysies » Sun Apr 08, 2012 7:51 am

Hello guys,

My name is Mysies and i am a beginner to c++. I don't very much, but i try to learn as much as i can.
I have a question to ask and that is how to make characters disappear.

so far my output looks like this:
zzz
zzz
zzz

But i want it to look like this:

zzz
zz
z

here is my c++ code:
Code: Select all
#include <iostream>
using namespace std;

int main()
{
   for(int a = 0; a < 3; a++)
   {
      for(int b = 0; b < 3; b++ )
      {
         cout << "z";      
      }
      cout << endl;
   }
   
   system("pause");
   return 0;
}


i have tried with:

for (int b = 3; b > 0; b--), but it just gives me the same output.

is there a way to make the characters disappear?
Mysies
 
Posts: 2
Joined: Sun Apr 08, 2012 7:20 am

Re: How to make characters disappear

Postby exomo » Sun Apr 08, 2012 10:22 am

There is no difference wether you run your loop from 0 to 2 or from 3 to 1, the result is the same because you repeat 3 times.
You get the desired result when you initialize b with the current value of a.
Code: Select all
for(int b = a; b < 3; b++ )
Who needs a signature anyway.
User avatar
exomo
 
Posts: 881
Joined: Fri Sep 26, 2003 12:30 pm
Location: germany->baden

Re: How to make characters disappear

Postby Mysies » Sun Apr 08, 2012 5:31 pm

Thank you so much exomo... that worked wonders for me.
I didnt think about the (int b = a), and now it makes very good sense.

Thank you exomo
Mysies
 
Posts: 2
Joined: Sun Apr 08, 2012 7:20 am


Return to For Beginners

Who is online

Users browsing this forum: No registered users and 1 guest