need ideas

Whether you're a newbie or an experienced programmer, any questions, help, or just talk of any language will be welcomed here.

Moderator: Coders of Rage

User avatar
dandymcgee
ES Beta Backer
ES Beta Backer
Posts: 4709
Joined: Tue Apr 29, 2008 3:24 pm
Current Project: https://github.com/dbechrd/RicoTech
Favorite Gaming Platforms: NES, Sega Genesis, PS2, PC
Programming Language of Choice: C
Location: San Francisco
Contact:

Re: need ideas

Post by dandymcgee »

killercoder wrote: I can't seem to figure out whats wrong with this code :(. it wont pause after you give you answer to last question....

P.S. It's a nooby mistake I bet lol.

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    int x = 0;
    int c = x + 5;
    string name;
    int answer1;
    cout << "what would you like your name to be?" << endl;
    cout << ">"; cin >> name;
    cout << "hello nice to meet you " << name << endl;
    cin.get();
    cout << "what is your favorite number " << name << endl;
    cout << ">"; cin >> x;
    cout << "Your favorite number is " << x << endl;
    cin.get();
    cout << "what is your favorite number +5?" << endl;
    cout << ">"; cin >> c;
    if( c != x+5 )
        cout << "Wrong@@@@" << endl;
    else if( c = x+5 )
        cout << "Correct!!" << endl;
    cin.get();
}
Try that.
Falco Girgis wrote:It is imperative that I can broadcast my narcissistic commit strings to the Twitter! Tweet Tweet, bitches! :twisted:
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: need ideas

Post by killercoder »

it still doesn't pause after you answer the last question :(
andrew
Chaos Rift Regular
Chaos Rift Regular
Posts: 121
Joined: Mon Dec 08, 2008 2:12 pm

Re: need ideas

Post by andrew »

Code: Select all

else if( c = x+5 )
That's a bad bug, watch out for those.

This is what you wanted:

Code: Select all

else if( c == x+5 )
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: need ideas

Post by killercoder »

thank you soooooooooooooooo much !!!!!!!!!!! :)
User avatar
short
ES Beta Backer
ES Beta Backer
Posts: 548
Joined: Thu Apr 30, 2009 2:22 am
Current Project: c++, c
Favorite Gaming Platforms: SNES, PS2, SNES, SNES, PC NES
Programming Language of Choice: c, c++
Location: Oregon, US

Re: need ideas

Post by short »

killercoder wrote:thank you soooooooooooooooo much !!!!!!!!!!! :)
Do you actually understand why his change works? It's important that you do.
My github repository contains the project I am currently working on,
link: https://github.com/bjadamson
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: need ideas

Post by killercoder »

Code: Select all

#include <iostream>
#include <string>

using namespace std;

int main(int argc, char *argv[])
{
    int x = 0;
    int c = x + 5;
    string name;
    int answer1;
    cout << "what would you like your name to be?" << endl;
    cout << ">"; cin >> name;
    cout << "hello nice to meet you " << name << endl;
    cin.get();
    cout << "what is your favorite number " << name << endl;
    cout << ">"; cin >> x;
    cout << "Your favorite number is " << x << endl;
    cin.get();
    cout << "what is your favorite number +5?" << endl;
    cout << ">"; cin >> c;
    if( c != x+5 )
        cout << "Wrong@@@@" << endl;
    else if( c == x+5 )
        cout << "Correct!!" << endl;
    cin.get();
}
this is seems correct but its not working i want it to puase after it says if your correct or not but it doesnt :(
killercoder
Chaos Rift Newbie
Chaos Rift Newbie
Posts: 29
Joined: Sat Oct 17, 2009 4:19 pm

Re: need ideas

Post by killercoder »

if I have a bug like that won't it cause a memory leak or something?

and that just says c is equal to x+5 not asking the question if it actually is equal to x+5
andrew
Chaos Rift Regular
Chaos Rift Regular
Posts: 121
Joined: Mon Dec 08, 2008 2:12 pm

Re: need ideas

Post by andrew »

The reason that piece of code is a bug is the '=' operator is actually the assignment operator. The '==' operator is used to test for equality. It's a very common error that the compiler doesn't catch, unless you have the warning level set to the highest.
User avatar
zeid
Chaos Rift Junior
Chaos Rift Junior
Posts: 201
Joined: Fri Apr 24, 2009 11:58 pm

Re: need ideas

Post by zeid »

if I have a bug like that won't it cause a memory leak or something?
No, memory leaks only occur when you dynamically allocate memory. You wont encounter them for a fair while until you are past understanding the basics.
Axolotl Pop!
Image
Or, try it for free.

For many more free games online visit www.sam-zeid.com
Post Reply