Author Topic: Learning C++! :D  (Read 3666 times)

OP, to make your programs easier, just add a line with:
using namespace std;
So you don't have to put std:: before the cout commands and stuff.
i have been told that already
ill do it when i want to

OP, to make your programs easier, just add a line with:
using namespace std;
So you don't have to put std:: before the cout commands and stuff.
I personally avoid doing that. I much rather include specific things that I will be using a lot, and for everything else use std::

Code: [Select]
#include <iostream>
#include <windows.h>
int main()
{
    using std::cout;

    cout << "Zuero: Hello, how are you today?\n";
    Sleep(1000);
    cout << "Jim: I'm doing well!\n";
    Sleep(1000);
    cout << "Zuero: Well that's fantastic!\n";
    Sleep(1000);
    cout << "Jim: Well okay, bye!\n";
    Sleep(1000);
    cout << "Zuero: Bye!\n";
    Sleep(1000);
    cout << "Zuero: Well he's a nice guy isn't he?\n";
    return 0;
}
ill be back from school
there are no bugs, just showing this

Code: [Select]
#include <iostream>
#include <windows.h>
int main()
{
    using namespace std;

    int yourEmotion;
    int yourStatulovee;
    char h;
    char s;
    char n;

    cout << "Enter which program to run: \n";
    cin >> yourStatulovee;
    Sleep(1500);
    cout << "Preparing to run yourStatus.exe...\n";
    Sleep(1000);
    cout << "Processing... This may take a few seconds.\n";
    Sleep(3000);
    cout << "Enter what your emotion is:   h = Happy s = Sad n = Neutral. \n";
    cin >> yourEmotion;
    if (yourEmotion == 'h')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Yay! You're happy! That's great!\n";
    if (yourEmotion == 's')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Aw, you're sad, why's that?\n";
    if (yourEmotion == 'n')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Well, it's okay to be neutral. No problems here.\n";

    return 0;
}
"warning: unused variable 'h' "
"warning: unused variable 's' "
"warning: unused variable 'n' "
dang it

-sneep-
"warning: unused variable 'h' "
"warning: unused variable 's' "
"warning: unused variable 'n' "
dang it

I am probably gonna sound like an idiot cause I have no knowledge of c++ but would string h; work?

Or did you forget "using std::cout;"?

I am probably gonna sound like an idiot cause I have no knowledge of c++ but would string h; work?

Or did you forget "using std::cout;"?
i did using namespace std;
hurrdurr

Code: [Select]
#include <iostream>
#include <windows.h>
int main()
{
    using namespace std;

    char yourEmotion;
    int yourStatulovee;

    cout << "Enter which program to run: \n";
    cin >> yourStatulovee;
    Sleep(1500);
    cout << "Preparing to run yourStatus.exe...\n";
    Sleep(1000);
    cout << "Processing... This may take a few seconds.\n";
    Sleep(3000);
    cout << "Enter what your emotion is:   h = Happy s = Sad n = Neutral. \n";
    cin >> yourEmotion;
    if (yourEmotion == 'h')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Yay! You're happy! That's great!\n";
    if (yourEmotion == 's')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Aw, you're sad, why's that?\n";
    if (yourEmotion == 'n')
        Sleep(1000);
        cout << "Processing...\n";
        Sleep(500);
        cout << "Well, it's okay to be neutral. No problems here.\n";

    return 0;
}

fixed

bool, int, double, float, char, string, etc, are all datatypes.
you were creating 3 character (char) variables, named h, s and n. you were also creating an integer (int) variable named yourEmotion
then you were testing an integer against a character
« Last Edit: September 06, 2011, 10:52:58 PM by blaman »

fixed

bool, int, double, float, char, string, etc, are all datatypes.
you were creating 3 character (char) variables, named h, s and n. you were also creating an integer (int) variable named yourEmotion
then you were testing an integer against a character
it did the same thing as before
i type in yourStatulovee then once it gets past "Processing... This may take a few seconds." it displays all of the stuff below it, youre supposed to say h s or n and it displays only that part

right I can't beleive I missed this, but please remember to put brackets after if statements.
if(condition here)
{
      do stuff here
}

right I can't beleive I missed this, but please remember to put brackets after if statements.
if(condition here)
{
      do stuff here
}
ok ill write that down on one of my "notes" papers

once it gets past "Processing... This may take a few seconds."
it displays "Enter what your emotion is:   h = Happy s = Sad n = Neutral."
then it tells me to press a key to end the program (im in code::blocks)

You should use a switch statement:

Code: [Select]
#include <iostream>
int main()
{
    enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, INSERTDAYHERE };

    Days today;
    today = INSERTDAYHERE;
    switch(today){
case Sunday:
std::cout << "\nToday is Sunday.\n";
break;
case Monday:
std::cout << "\nToday is Monday.\n";
break;
case Tuesday:
std::cout << "\nToday is Tuesday.\n";
break;
case Wednesday:
                std::cout << "\nToday is Wednesday.\n";
break;
case Thursday:
std::cout << "\nToday is Thursday.\n";
break;
case Friday:
std::cout << "\nToday is Friday.\n";
break;
case Saturday:
std::cout << "\nToday is Saturday.\n";
case INSERTDAYHERE:
std::cout << "\nYou need to set what day it is in the code!\n";
}

    int x;
    std::cin >>x;
    return 0;
}
« Last Edit: September 07, 2011, 08:29:01 AM by Scars75 »

You should use a switch statement:

Code: [Select]
#include <iostream>
int main()
{
    enum Days { Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, INSERTDAYHERE };

    Days today;
    today = INSERTDAYHERE;
    switch(today){
case Sunday:
std::cout << "\nToday is Sunday.\n";
break;
case Monday:
std::cout << "\nToday is Monday.\n";
break;
case Tuesday:
std::cout << "\nToday is Tuesday.\n";
break;
case Wednesday:
                std::cout << "\nToday is Wednesday.\n";
break;
case Thursday:
std::cout << "\nToday is Thursday.\n";
break;
case Friday:
std::cout << "\nToday is Friday.\n";
break;
case Saturday:
std::cout << "\nToday is Saturday.\n";
case INSERTDAYHERE:
std::cout << "\nYou need to set what day it is in the code!\n";
}

    int x;
    std::cin >>x;
    return 0;
}
thats the wrong code
thats dayteller
im not asking for help on it

thats the wrong code
thats dayteller
im not asking for help on it
ik it's dayteller
I was just giving you a tip for when you make other programs


for once i fixed the bugs myself