Stumped already!

Mar 9, 2010 at 4:11am
Hello, I've just begun my first tutorial. I've writtin out a piece of code identical to the one in the tutorial but when I try to compile and run it it gives me an error( http://i.imagehost.org/view/0883/er ).

Heres my code and then the original:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include<iostream>
#include<string>
using namespace std;      //introduces namespace std

string yell = "A dragon is coming, take cover!!!";

int main(void)
{
   cout<< yell.c_str() <<end1
       << yell.c_str() <<end1
       << yell.c_str() <<end1
       << yell.c_str() <<end1;
    system("PAUSE");
    
    return 0;
}


In my code I added the system pause so the command prompt stays open. This works fine if I add it to the original code.

Original Code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
#include<string>
using namespace std;      //introduces namespace std

string yell = "A dragon is coming, take cover!!!";

int main(void)
{
    cout<< yell.c_str() <<endl
        << yell.c_str() <<endl
        << yell.c_str() <<endl
        << yell.c_str() <<endl;
    
    return 0;
}


The original compiles just fine but my code which I looked over and over at appears to be identical yet it won't compile.

I'm sorry if this is completely stupid and blatantly obvious but I've been trying to figure this out for an hour or so.
Mar 9, 2010 at 4:15am
closed account (jwC5fSEw)
You've typed end1 when it's actually endl.
Mar 9, 2010 at 4:20am
Jeesh way to simple yet frustrating. Thanks a lot.

<---feels stupid now
Mar 9, 2010 at 4:26am
closed account (jwC5fSEw)
Don't worry, as a fellow beginner, I've also made my share of silly mistakes. The great part about this forum is that the veteran members will take you seriously and help you learn. I'd say this forum has been the most informative part of my whole C++ learning process so far.
Mar 9, 2010 at 5:26am
<---feels stupid now


Don't worry...I didn't see that either >_>

Protip: Use a font that has different l 1 o O and 0 ;)
Mar 9, 2010 at 5:59am
Thanks everyone. :)

I wrote another simple thing here, only thing I couldn't fiqure out how to do is to have it say " x + y = z" so I just made it say "Those two numbers = x".





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include <iostream>
using namespace std;      //introduces namespace std


int main( void )
{
    string pname = "";
    int x1;
    int y1;
    string exit;

    cout<< "What is your name?"<< "      ";
    cin>>pname;           
    cout<<endl<< "Hello " << pname.c_str() <<endl;
    cout<<endl<< "Please give me a number   ";           
    cin>> x1;
    cout<< "One more number please    ";            
    cin>> y1;
    cout<<endl<< "Those two numbers equal   "
        <<( x1 + y1 ) << " ! ! "  <<endl <<endl; 
    cout<< "Type and enter anything to exit this great program!";
    cin>>exit;
    return 0;
}



This is more entertaining then I thought it would be, I should of started doing this long ago! :)
Last edited on Mar 9, 2010 at 6:05am
Mar 9, 2010 at 6:23am
Just put that into cout:

cout<<"x + y = "<<x1+y1<<"\n";
Mar 9, 2010 at 6:43am
What I meant was x and y being the input numbers from the user. I tried a few things but it all failed.

Though it doesn't really matter at this point, I'm only a few hours into this and this doesn't seem too hard a task to learn.
Last edited on Mar 9, 2010 at 6:47am
Mar 9, 2010 at 7:00am
Ah, then you can just output it like you would any other variable:

cout<<x<<" + "<<y<<" = "<<x+y<<"\n";
Mar 9, 2010 at 8:16am
Thanks! I made something similar too that except I did not put the required <<'s (whatever their called).

Also I don't know what the "\n" does.

ty for the helps.:)
Last edited on Mar 9, 2010 at 8:20am
Mar 9, 2010 at 8:27am
means new line
Topic archived. No new replies allowed.