Stumped already!

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.
closed account (jwC5fSEw)
You've typed end1 when it's actually endl.
Jeesh way to simple yet frustrating. Thanks a lot.

<---feels stupid now
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.
<---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 ;)
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
Just put that into cout:

cout<<"x + y = "<<x1+y1<<"\n";
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
Ah, then you can just output it like you would any other variable:

cout<<x<<" + "<<y<<" = "<<x+y<<"\n";
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
means new line
Topic archived. No new replies allowed.