0

I use the same compiler that's in C::B (mingw, which is the port of the Gnu Compiler Collection to Windows) from the command line for shorter projects and VC++ Express Edition for projects of more than a few files. C::B is a great program but I wasn't using many of the features.

You have to use what you feel comfortable with. Any setup will have it's gotchas. VC++ EE has a great debugger right of the bat. C::B has gdb which is awesome (I envy those who use it effectively) but has somewhat of a learning curve) and seems to integrate well with the environment.

Check out this thread too!

Edited by jonsca: n/a

0
int main()
{
using namespace std;

int x;
cout << "how many legs do you have?" << endl;
cin >> x;

switch (x)
{
case 1:
cout << "thats weird..." << endl;
break;
case 2:
cout << "your normal..." << endl;
break;
case 3:
cout << "ya freak!!!!!!!!!" << endl;
break;
default:
        cout << "i dont know what you are..." << endl;
       }

system("pause");
return 0;
}

so i put this code into the code::blocks program and tried to run it.
it came up with the error: 'cout' was not declared in this scope

whats causing this? i have the same exact script in dev c++ and its working fine...

0

ok i just made a new script using structures and this is what i got:

#include <iostream>
#include <cmath>

struct newperson
{
    char person[20];
    char name[20];
    int age;
    };


int main()
{
using namespace std;

newperson bob =
{
    "this is bob",
    "Bob's age is:",
    36
    };
cout << bob.person << endl;
cout << bob.name << endl;
cout << bob.age << endl;
newperson jimmy =
{
    "this is Jimmy",
    "Jimmy's age is:",
    48
    };
cout << jimmy.person << endl;
cout << jimmy.name << endl;
cout << jimmy.age << endl;
system("pause");
return 0;
}

this works and all but i want to add a person to the side of: this is bob, and this is jimmy.
something like this:
O
\ /
|
/ \
well thats the best one i can think of how to make with /'s and stuff right now... i tried this:
cout << " O
\ /
|
/ \" << endl
but that didnt work...

Edited by skorm909: n/a

0

havnt learned strings yet i dont think, but now i got some code:

#include <iostream>
#include <cmath>
#include <fstream>
#include <cstdlib>


struct peoples
{
    char person[20];
    char stick[80];
    char discrip[20];
    int age;
    };
int main()
{
using namespace std;

peoples = 
{
    "this is bob:",
    "file for stickfigure here",
    "bob's age is: ",
    36
    }

system("pause");
return 0;
}

and what i want to do for this is in "file for stickfigure here"
basically have a stick figure in the program then move onto the next line so it would endup being like this...

this is bob.
(stick figure here)
bob's age is:
36

is there a way i can do this?

0

havnt learned strings yet i dont think, but now i got some code:

#include <iostream>
#include <cmath>  [B]//Don't need it[/B]
#include <fstream> [B]//Don't need it[/B]
#include <cstdlib> [B]//Don't need it[/B]


struct peoples
{
    char person[20];
    char stick[80];  [B]//See below[/B]
    char discrip[20];
    int age;
    };
int main()
{
using namespace std;   [b] //Needs to be outside of main [/b]

peoples =       //[b] need an instance now, see below[/b]
{
    "this is bob:",
    "file for stickfigure here",
    "bob's age is: ",
    36
    }

system("pause"); [b] //lose this bad habit before you pick it up[/b]
return 0;
}

See my changes below:

struct peoples
{
    char person[20];
    char stick[3][6];  //3 rows of 6 columns
    char discrip[20];
    int age;
    };
int main()
{
     peoples mypeople=        //making a struct mypeople 
      {                                  //that is of type peoples
            "this is bob:",
           {"\\ O /",           //initializing 2D array inside
               "  | ",             //HW: why do we need \\ for a backslash
               "/  \\"},
          "bob's age is: ",
            36
     };
     return 0;
}

My code above needs the #include and using statements

Don't use system("pause"); see this use cin.get(); which will wait for a key.

Edited by jonsca: n/a

0

ok and i made this today, it converts your age into dog years then asks some questions but what i want to know is if i have the questions, how do i make it so if they get it wrong it says wrong, then to the side add a point to the right/wrong.
so have it like:
question: ssfgesg
answer: sgesg
right. 1/1
question: wgsgseg
answer: shesh
wrong: 1/2
then total score= 1/2
something like that...
anyway heres the code:

#include <iostream>
#include <cmath>

int main()
{
using namespace std;
    
int hi;
int name;
int years;
int house;
int yellow;
int blue;
int green;
cout << "to find out your age in dog years, type in your age:" << endl;
cin >> hi;
cout << "calculating..." << endl;
cout << "your age in dog years is..." << endl;
cout << hi * 7 << endl;  
cout << "if the green house is made of green bricks, what color are the stairs?" << endl;
cout << "pick one, 1. green , 2. blue , 3. yellow , 4. how would i know?" << endl;
cin >> green;
if ( green == 1 || green == 1.) cout << "Correct!!" << endl;
else cout << "wrong..." << endl;
cout << "if the yellow house is made of yellow bricks, what color are the doors?" << endl;
cout << "pick one, 1. green , 2. blue , 3. yellow , 4. how would i know?" << endl;
cin >> yellow;
if ( yellow == 3 || yellow == 3.) cout << "Correct!!" << endl;
else cout << "wrong..." << endl;
cout << "if the blue house has everything made of blue... what is it made out of?" << endl;
cout << "pick one, 1. blue bricks , 2. yellow bricks , 3. green bricks , 4. glass" << endl;
cin >> blue;
if ( blue == 4. || blue == 4) cout << "CORRECT! You win!!!!" << endl;
else cout << "you suck, go do it again." << endl;

    
    
system("pause");
return 0;    
    
}
0

if ( green == 1 || green == 1.) There is no such thing as 1. with an integer. Just use if (green == 1) For keeping track, make another integer variable called correct and one called total or something like that. Set them both to 0 when you declare them (so int correct = 0; ).

if(green == 1)
{
       cout<<"Correct"<<endl;
       correct++;   //shorthand for correct = correct + 1;
} //need the braces for multiple statements under one if

else
      cout <<"Wrong"<<endl;

total++;  //after both if and else are done

cout <<"You have "<<correct<<"/"<<total<<endl;

if(yellow == 3)
{
     cout <<"Correct"<<endl;
     correct++;    //don't redeclare it or set it to 0 again
}
else
      cout<<"Wrong"<<endl;

total++;


cout <<"You have "<<correct<<"/"<<total<<endl;

Repeat that for as many as you want.

You're starting to get it ok. Keep reinforcing what you are learning but don't be afraid to delve further into the language so you can expand your repertoire.

Edited by jonsca: n/a

0

ok thanks i had to add:

int correct;
int total;


correct = 0;
total = 0;

then after that i just followed what you said and it all worked out fine,
thanks =).

now i just have to figure out what else to add....
any ideas?

just like, give me an idea and see if i can do it without help.

Edited by skorm909: n/a

0

You can declare and initialize on the same line:

int correct = 0;
int total = 0;

As far as your "assignment" I say let creativity be your guide and look up features of the language you think you need. Try to also follow something like a tutorial or a book to bring some structure to your studying.

0

You can declare and initialize on the same line:

int correct = 0;
int total = 0;

As far as your "assignment" I say let creativity be your guide and look up features of the language you think you need. Try to also follow something like a tutorial or a book to bring some structure to your studying.

well what i was wanting to do is like have a program that pops up and has buttons to run different code i made but everytime i try looking on how to do this i can never find anything...

as for right now i want to make it so its kind of a game where i have the questions and depending on the score at the end they either have to redo the questions or go to a new set...
so would that be like:

if (correct == >3)
//then something like run to the next line of code, isnt there like a skip function i can use to do this?
// then
if (correct == <3)
// then something like run a loop back to the beginning of the questions....
1

have a program that pops up and has buttons to run different code i made

Unless you've got some GUI experience in another language that's going to be a bit of a road...give it time.

i want to make it so its kind of a game where i have the questions and depending on the score at the end they either have to redo the questions or go to a new set...

That's going to take some strings knowledge. Grab some tutorials. Start simple. Look into arrays to store your questions. Look into files to store additional sets of questions.

correct == >3
correct ==<3

See if you can figure out what's wrong with those two statements.

Edited by jonsca: n/a

Votes + Comments
You've got patience, you can make an excellent teacher :) ..
0

Ohhh...

correct => 3
correct =< 3

I think I got the order wrong thought

0

It may seem silly but just say them out loud if you forget "greater than > or equal = to", >= and "less than < or equal = to", <=

0

ya i was thinking it was like that... not sure exactly what im going to make thought about the question one but... cant think of anything else

0

Search around on this site for "text based RPG." People early on in their programming seem to really enjoy creating though without using functions and the like they can get a little unwieldy. I know a user named Restrictment had posted the code for his some months back. It couldn't hurt just to look at it and see where he went with it.

0

ok thanks,
in my history class we got an assignment to do a quarter project however we want,
i figured since i started c++ and i know the basics of javascript too, why not try and make a website with html?
i think if i did it on a free site that makes it for you and all that it wouldnt mean as much,
can i import some of my c++ things into the html site or is that only for javascript too?
also if you know any places where i can find tutorials for html or javascript i would really appreciate it...

0

C++ won't help you really at all with web stuff (though there are some technologies like this which allow users to run C code in the browser). C# (which is related to C++) can be used in ASP.NET coding on the web.

In terms of tutorials for HTML and Javascript (which is a smidge like C++ actually) I would pop over to the folks in the DaniWeb Web Development forums and see what they have for sticky threads over there. I'd imagine there are quite a few. I went through some of the w3schools material at one point and I found it pretty well laid out but definitely see what they recommend first.

0

ok thanks i may come back to this page if i got any questions about c++ again =) either that or i might just message you well if thats ok...
thanks for your help though

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.