Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Clear Screen/Review
Index -> Programming, C++ -> C++ Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Flikerator




PostPosted: Tue Jul 26, 2005 7:47 pm   Post subject: Clear Screen/Review

I didn't get to practise C++ yesterday so I am today. I decided to do some review without looking at any of my old programs or tutorials. Its all from my head. I used vars, loops, and if statements to make this. Its not really good for anything, but its just for review. There is only one thing missing, if you notice it still has the old question when it starts over...

How do I clear the screen of everything? cls is used in Turing (So you know what im talking about).

I skimmed through the lessons im doing and they don't have it. Im learning functions next (making my own) but I just wanted to know how to clear the screen.

code:

#include <iostream>
int main()
{
 int age,x;
 x=0;
 
 do {
  std::cout << "Enter your age: ";
  std::cin >> age;
  std::cin.ignore();
 
  if (age > 55) {
     std::cout << "\nYou are really old!" << std::endl;
     }
  else if (age <= 54) {
      std::cout << "\nI know toothpicks older then you!" << std::endl;
      }
  std::cin.get();
 }while (x == 0);
}
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Tue Jul 26, 2005 9:17 pm   Post subject: (No subject)

Use the Search button, it saves other people work.

You should only be clearing the screen if you really need to. Give one valid reason why you should be clearing the screen in any program you are making. If you can't then you really shouldn't be using it.

http://www.compsci.ca/v2/viewtopic.php?p=78687&highlight=clear+screen#78687

Now, as for your program...
You should try to avoid using do while loops, stick to for and while loops as long as you can. A do while loop can cause confusion and problems because it always goes through the actions at least once. Instead of wasting the variable and bad loop, just do:
c++:
for ( ; ; )

for an infinite loop.

Finally, you should really try using clearer syntax. Whenever you start a new bracket '{' '}' you should press 'enter'.
wtd




PostPosted: Tue Jul 26, 2005 11:08 pm   Post subject: (No subject)

As Gandalf says, in a text-based UI, there is no good reason to clear the screen. The user knows what he or she input. Hiding it from them later won't change that.

There's also no cross-platform way to do it.
Flikerator




PostPosted: Thu Jul 28, 2005 12:05 am   Post subject: (No subject)

What I mean for clear screen is;

code:

IN TURING

var num : int

loop
    put "Enter your age"
    get age
    cls
end loop


apposed to;

code:

IN TURING

var num : int

loop
    put "Enter your age"
    get age
end loop


It just looks a lot neater when its asked the second time, third time ext.

As for the bracket thing I just did what was on the site, ill keep it in mind though. Ty.
1of42




PostPosted: Thu Jul 28, 2005 1:10 am   Post subject: (No subject)

[Gandalf] wrote:
Now, as for your program...
You should try to avoid using do while loops, stick to for and while loops as long as you can. A do while loop can cause confusion and problems because it always goes through the actions at least once. Instead of wasting the variable and bad loop, just do:


Frankly, do-while is no more confusing than either of the other 2 variants of loops - it has its own uses just as the other 2 do. It's not confusing or problematic, as long as you take the 2 seconds to figure out what it does.
[Gandalf]




PostPosted: Thu Jul 28, 2005 5:34 pm   Post subject: (No subject)

Flikerator: We know what you are talking about, but you shouldn't waste the clear screen when you don't need it. It's like that for any command. Like wtd said, the user knows they have inputted 40 numbers - no need to hide that.

1of42: Here, I think this will illustrate what I mean. Try and predict what it will output before compiling it. You may just be wrong Smile.
c:
#include <stdio.h>

main()
{
        int counter_1 = 0;
        int counter_2 = 0;
        int counter_3 = 0;
        int exit;

        for(counter_1 = 0; counter_1 <= 2; counter_1++)
        {
                while(counter_2++ <= 3)
                {
                        do
                        {
                                printf("counter_1 = %d\n",counter_1);
                                printf("counter_2 = %d\n",counter_2);
                                printf("counter_3 = %d\n",counter_3);
                        }
                        while(counter_3++ <= 3);
                }
        }
        scanf("%d", exit);
}

do while loops have their uses, but if you don't need one I would avoid it.

*edits* couldn't get that scanf right heh.
wtd




PostPosted: Thu Jul 28, 2005 5:42 pm   Post subject: (No subject)

[Gandalf] wrote:
do while loops have their uses, but if you don't need one I would avoid it.


Always use the right tool for the job.
Display posts from previous:   
   Index -> Programming, C++ -> C++ Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 7 Posts ]
Jump to:   


Style:  
Search: