Discussion 9-27

More practice with cout

Find the error!

We pulled up a list of C++ programs with simple mistakes and tried to figure out where the mistakes were.

It's good practice to find the mistakes just by looking at the code, and even to try to guess what the errors will say. To check for sure, you can always copy-paste into Visual Studio and try to build + run.

In class we got up through problem 5, but trying the rest on your own is recommended!

Problem 1

using namespace std;

int main() {
    cout << "Hello World!\n";
    return 0;
}

Problem 2

#include<iostream>
using namespace std;

int main(); {
    cout << "Hello World!\n";
    return 0;
}

Problem 3

#include<iostream>
using namespace std;

int main() {
    cout << "Hello World!\n"
    return 0;
}

Problem 4

#include<iostream>

int main() {
    cout << "Hello World!\n";
    return 0;
}

Problem 5

#include<iostream>
using namespace std;

int main() {
    cout << "Hello World!\n";
    return;
}

Problem 6

#include<iostream>
using namespace std;int main()

        {
        cout << "Luke, I am your father." << "\n"
                                         return 0;
                                   }

Problem 7

#include<iostream>
using namespace std;

int main() {
        cout >> "Toto, I've got a feeling we're not in Kansas anymore." >> "\n";
      return 0;
}

Problem 8

#include<iostream>
using namespace std;

int main() {
    cout << "You talking to me?"\n;
    return 0;
}

Problem 9

#include<iostream>
using namespace std;

int main() {
    cout << "What we've got here is failure to communicate." << \n;
    return 0;
}

Problem 10

#include<iostream>
using namespace std;

int main() {
    cout << I love the smell of napalm in the morning. << "\n";
    return 0;
}

Problem 11

#include<iostream>
using namespace std;

int main() {
    Cout << "Love means never having to say you're sorry.\n";
    return 0;
}

Problem 12

#include<iostream>
using namespace std;

int main() {
    cout << "You don't understand!\n"
         << "I coulda had class.\n";
         << "I coulda been a contender.\n"
         << "I could've been somebody, instead of a bum, which is what I am.\n";
    return 0;
}

Problem 13

#include<iostream>
using namespace std;

int main() {
    return 0;
    cout << "Yo.";
}

Google searches

If you have trouble with your code, you can always ask me for help... BUT a really useful programming-related skill is the ability to find the answer on the internet. (Note that the code you hand in for HW shouldn't use any commands that we haven't covered in class.)

Here are some Google searches you could try if you're having trouble with today's material. I'm deliberately trying to choose search terms that you could have thought of yourself!