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

Username:   Password: 
 RegisterRegister   
 The output of my program isn't what I want it to
Index -> Programming, C++ -> C++ Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Cancer Sol




PostPosted: Sat Mar 16, 2013 7:37 pm   Post subject: The output of my program isn't what I want it to

c++:

#include <iostream>
using namespace std;

int main ()
{
    cout << "     )                      " << endl
         << "  ( /(                      " << endl
         << "  )\())    )         (  (   " << endl
         << " ((_)\ ( /(   (     )\))(  " << endl
         << "__ ((_) )(_))  )\ ) ((_))\ " << endl
         << "\ \ / /((_)_  _(_/(  (()(_) " << endl
         << " \ V / / _` || ' \))/ _` |  " << endl
         << "  |_|  \__,_||_||_| \__, |  " << endl
         << "                    |___/   " << endl;
}

It's supposed to output a big "Yang" that looks kinda on fire, but after being compiled and when I run it, it's really messed up. Is it because of my compiler?
I'm using GNU GCC compiler btw.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Sat Mar 16, 2013 7:42 pm   Post subject: RE:The output of my program isn\'t what I want it to

That doesn't even compile.

Quote:

tony$ g++ /tmp/wut.cpp
/tmp/wut.cpp: In function ?int main()?:
/tmp/wut.cpp:9: error: unknown escape sequence: '\040'
/tmp/wut.cpp:9: error: unknown escape sequence '\)'
/tmp/wut.cpp:10: error: unknown escape sequence: '\040'
/tmp/wut.cpp:10: error: unknown escape sequence: '\040'
/tmp/wut.cpp:11: error: unknown escape sequence: '\040'
/tmp/wut.cpp:11: error: unknown escape sequence: '\040'
/tmp/wut.cpp:12: error: unknown escape sequence: '\040'
/tmp/wut.cpp:12: error: unknown escape sequence '\)'
/tmp/wut.cpp:13: error: unknown escape sequence '\_'
/tmp/wut.cpp:13: error: unknown escape sequence '\_'
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
TZak




PostPosted: Sat Mar 16, 2013 7:56 pm   Post subject: Re: The output of my program isn't what I want it to

I've never coded in c++ and even I know this. Here take a look at this:

Quote:

#include <iostream>
using namespace std;

int main ()
{
cout << " ) " << endl
<< " ( /( " << endl
<< " )\\()) ) ( ( " << endl
<< " ((_)\\ ( /( ( )\\))( " << endl
<< "__ ((_) )(_)) )\\ ) ((_))\\ " << endl
<< "\\ \\ / /((_)_ _(_/( (()(_) " << endl
<< " \\ V / / _` || ' \\))/ _` | " << endl
<< " |_| \\__,_||_||_| \\__, | " << endl
<< " |___/ " << endl;
}


The problem with your code is that the strings contain the escape character ("\"). I won't explain what it does, but to use it in a string you must type in two of them ("\\") and thus your output will only display as one.
Cancer Sol




PostPosted: Sat Mar 16, 2013 7:58 pm   Post subject: Re: The output of my program isn't what I want it to

TZak @ 3/16/2013, 7:56 pm wrote:
I've never coded in c++ and even I know this. Here take a look at this:

Quote:

#include <iostream>
using namespace std;

int main ()
{
cout << " ) " << endl
<< " ( /( " << endl
<< " )\\()) ) ( ( " << endl
<< " ((_)\\ ( /( ( )\\))( " << endl
<< "__ ((_) )(_)) )\\ ) ((_))\\ " << endl
<< "\\ \\ / /((_)_ _(_/( (()(_) " << endl
<< " \\ V / / _` || ' \\))/ _` | " << endl
<< " |_| \\__,_||_||_| \\__, | " << endl
<< " |___/ " << endl;
}


The problem with your code is that the strings contain the escape character ("\"). I won't explain what it does, but to use it in a string you must type in two of them ("\\") and thus your output will only display as one.

Oh crap... I feel so newbie :3 I am a noob anyways though xD
Thanks a lot!

@Tony Well idk why, but it worked for me though :/

Goddamnit... it makes the code look so messyy now, and on the console, it looks bad Sad
Time to change how it looks Razz
Tony




PostPosted: Sat Mar 16, 2013 8:09 pm   Post subject: Re: The output of my program isn't what I want it to

the escape character exists so that one can describe special characters

\n -- new line
\t -- tab

etc.

Of course that leaves us with a single problem -- how to describe a sequence of characters "\n" as backslash.n instead of newline? Well, you escape the escape character! \\n

Cancer Sol @ Sat Mar 16, 2013 7:58 pm wrote:
@Tony Well idk why, but it worked for me though :/

Show that Wink
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cancer Sol




PostPosted: Sun Mar 17, 2013 8:14 pm   Post subject: Re: The output of my program isn't what I want it to

Tony @ 3/16/2013, 8:09 pm wrote:
the escape character exists so that one can describe special characters

\n -- new line
\t -- tab

etc.

Of course that leaves us with a single problem -- how to describe a sequence of characters "\n" as backslash.n instead of newline? Well, you escape the escape character! \\n

Cancer Sol @ Sat Mar 16, 2013 7:58 pm wrote:
@Tony Well idk why, but it worked for me though :/

Show that Wink


I don't like using \n, it makes my code look kinda confusing to me :/
I always thought \t was useless because I could just press tab myself, but I just remembered, pressing tab doesn't do anything to the output xD

Here's the screenshot: http://i50.tinypic.com/2i8xa9g.jpg Wink
Tony




PostPosted: Sun Mar 17, 2013 8:18 pm   Post subject: RE:The output of my program isn\'t what I want it to

looks like escape sequences are simply discarded instead of getting caught by strict errors.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cancer Sol




PostPosted: Sun Mar 17, 2013 8:35 pm   Post subject: Re: The output of my program isn't what I want it to

Was I only able to compile it because my compiler discarded them?
Just wondering though, did you compile it with GNU GCC compiler or was it a different one?
Sponsor
Sponsor
Sponsor
sponsor
wtd




PostPosted: Sun Mar 17, 2013 8:53 pm   Post subject: RE:The output of my program isn\'t what I want it to

It compiled because it's a valid program; just not the one you meant to write. The issue is compiler-independent.
Tony




PostPosted: Sun Mar 17, 2013 8:53 pm   Post subject: RE:The output of my program isn\'t what I want it to

Quote:

tony$ g++ --version
i686-apple-darwin10-g++-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5666) (dot 3)
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Cancer Sol




PostPosted: Mon Mar 18, 2013 12:07 pm   Post subject: Re: The output of my program isn't what I want it to

No wonder, I thought I might've posted the wrong code actually before I tested the program again Razz

Does it differ if I'm using Windows or an ios based operating system?
and I've always wondered this, what's a linux? I've never really seen it before :/
DemonWasp




PostPosted: Mon Mar 18, 2013 12:37 pm   Post subject: RE:The output of my program isn\'t what I want it to

Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...).

Linux is an operating system kernel. It's bundled with a lot of utilities made by the GNU group, so properly the base operating system is called GNU/Linux, though most people just call it Linux. There are hundreds or thousands of "distributions" of Linux, each of which gives you a slightly different user interface and set of programs.

So, when people say "linux", they usually mean "a distribution of the GNU/Linux base system, with a bunch of other stuff on top".

Nearly all distributions are free and open-source. Support is generally not free, but there are communities that offer support for each distribution. You can install most distributions by downloading a CD or DVD image, burning it to disk, putting that disk in the drive and rebooting (subject to BIOS boot order and a lot of complexity I won't get into here).

There are a few much-more-popular desktop distributions, including Ubuntu, Mint, and Debian (all in the same "family", with Debian being the "father"). Android is based on Linux. With Ubuntu and Mint, you can download a "LiveCD", which is just a disk that you can start the operating system from, without needing to permanently change anything about your existing computer setup.
wtd




PostPosted: Mon Mar 18, 2013 9:48 pm   Post subject: Re: RE:The output of my program isn\'t what I want it to

DemonWasp @ Tue Mar 19, 2013 1:37 am wrote:
Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...).


Technically correct, but irrelevant when used to compile basic programs.
Cancer Sol




PostPosted: Wed Mar 20, 2013 6:48 pm   Post subject: Re: RE:The output of my program isn\'t what I want it to

DemonWasp @ 3/18/2013, 12:37 pm wrote:
Compiler specifics vary wildly between the various platforms (operating system and CPU-type combinations, such as Windows on x86, Windows on x64, Linux x86, Linux ARM, Linux Sparc, Linux PowerPC, Linux x64, Linux Itanium, ...).

Linux is an operating system kernel. It's bundled with a lot of utilities made by the GNU group, so properly the base operating system is called GNU/Linux, though most people just call it Linux. There are hundreds or thousands of "distributions" of Linux, each of which gives you a slightly different user interface and set of programs.

So, when people say "linux", they usually mean "a distribution of the GNU/Linux base system, with a bunch of other stuff on top".

Nearly all distributions are free and open-source. Support is generally not free, but there are communities that offer support for each distribution. You can install most distributions by downloading a CD or DVD image, burning it to disk, putting that disk in the drive and rebooting (subject to BIOS boot order and a lot of complexity I won't get into here).

There are a few much-more-popular desktop distributions, including Ubuntu, Mint, and Debian (all in the same "family", with Debian being the "father"). Android is based on Linux. With Ubuntu and Mint, you can download a "LiveCD", which is just a disk that you can start the operating system from, without needing to permanently change anything about your existing computer setup.


You can use Linux on a windows computer then?
Insectoid




PostPosted: Wed Mar 20, 2013 6:54 pm   Post subject: RE:The output of my program isn\'t what I want it to

You can replace Windows with Linux on a computer. Or you can give your computer the option to use either Windows or Linux if you want to.
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 2  [ 16 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: