help?

This is a discussion on help? within the C++ Programming forums, part of the General Programming Boards category; Anthing i need to change for it to work the compiler is going crazy on something that looks ok so ...

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    5

    help?

    Anthing i need to change for it to work the compiler is going crazy on something that looks ok so i can test.


    Code:
    #include <iostream>
    #include <stdio.h>
    
    using namespace std;
    
    int num , rand_max ;
    int main()
    {
    cout<< "Welcome to the rs magic 8 balll" ;
    int num = rand() % 10 + 1;
    
     While ( num=> 0 || num=<  10);
     
    num = rand()
    
    
    If num = 0;
     cout<< " Go mine and smith" ;
    else
    if num = 1;
    cout<< " Find a party and go noob hunting" ;
    else
     If num = 2;
    count<< " Get your range gear and go kill blk demons";
    else
     If num = 3;
    count<< " Head to Castle Wars with mates";
    else
     If num = 4;
    count<< " Go to Karmaja on f2p and fish annoy high lvls while there";
    else
     If num = 5;
    count<< " Go cut the highest wood you can and sell";
    else
     If num = 6;
    count<< " Get a War Hammer and bash goblins";
    else
     If num = 7;
    count<< " Head to dueling arena to train";
    else
     If num = 8;
    count<< " Grab Runes and mage guards";
    else
     If num = 9;
    count<< " Login on a noob account and pester everyone";
    else
     If num = 10;
    count<< " Hunt for Bob the Jagex Cat";
    else
     return 0 ;

  2. #2
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    When you made the program, did you ever even compile it except at the end?
    Compile often, ever several minutes or so.
    Also, you should have been able to get rid of some of the errors, you need to read over the tutorials some more

    because I'm nice , here's an improved version
    Code:
    #include <iostream>
    #include <time.h>
    #include <stdio.h>
    
    using namespace std;
    
    int main()
    {
    	srand(time(NULL));
    	int num;
    	cout<< "Welcome to the rs magic 8 ball\n" ;
    	num = rand() % 11;
    	switch(num)
    	{
    	case 0:
    		cout<< " Go mine and smith\n";
    		break;
    	case 1:
    		cout<< " Find a party and go noob hunting\n";
    		break;
    	case 2:
    		cout<< " Get your range gear and go kill blk demons\n";
    		break;
    	case 3:
    		cout<< " Head to Castle Wars with mates\n";
    		break;
    	case 4:
    		cout<< " Go to Karmaja on f2p and fish annoy high lvls while there\n";
    		break;
    	case 5:
    		cout<< " Go cut the highest wood you can and sell\n";
    		break;
    	case 6:
    		cout<< " Get a War Hammer and bash goblins\n";
    		break;
    	case 7:
    		cout<< " Head to dueling arena to train\n";
    		break;
    	case 8:
    		cout<< " Grab Runes and mage guards\n";
    		break;
    	case 9:
    		cout<< " Login on a noob account and pester everyone\n";
    		break;
    	case 10:
    		cout<< " Hunt for Bob the Jagex Cat\n";
    		break;
    	default:
    		return 0;
    	}
    	return 0;
    }
    Last edited by MadCow257; 04-08-2005 at 06:45 PM. Reason: spelling error

  3. #3
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    I think you need some review on basic C++ syntax. Your while loop is wrong, your if statements and conditions are wrong, and you're missing a closing brace at the end of main.

    And next time post the compiler errors as well.
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  4. #4
    Registered User
    Join Date
    Sep 2004
    Posts
    36
    Here is ur problem.

    Look at where ur variables are declared.

    Also in order to use random, add this piece of code at the beginning of the main() function. Include the <time.h>, <stdlib.h>, <string.h> and <conio.h> libraries please.

    Code:
    time_t t;
    srand((unsigned) time(&t));
    Another error is right underneath the while loop. It should say

    Code:
    num=rand()%10+1;
    Then, ur while loop is all messed up. Remove the semicolon after the while statement, and add "{" and "}" for the body of the loop.

    Uncapitalize the "w" in while.
    The while argument is wrong.
    Below is the correct code.

    Code:
    while ( num>= 0 || num<=  10)
    {
    
    body of the loop with ur if ladder that u have
    }
    -----------------------------------------------------------------------------------------------------------------------------------------------------------------------

    This is ur debugged code.

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <time.h>
    #include <stdlib.h>
    
    using namespace std;
    
    
    int main()
    {
    
    time_t t;
    srand((unsigned) time(&t));
    
    int num , rand_max ;
    
    cout<< "Welcome to the rs magic 8 balll" ;
    int num = rand() % 10 + 1;
    
    
     while ( num>= 0 || num<=  10)
    {
     
    num = rand() &10+1;
    
    
    If (num = 0)
    {
     cout<< " Go mine and smith" ;}
    
    else if (num = 1)
    {
    cout<< " Find a party and go noob hunting" ;}
    
    else if (num = 2){
    count<< " Get your range gear and go kill blk demons";}
    
    else if (num = 3){
    count<< " Head to Castle Wars with mates";
    }
    else if (num = 4){
    count<< " Go to Karmaja on f2p and fish annoy high lvls while there";
    }
    
    else (if num = 5){
    count<< " Go cut the highest wood you can and sell";}
    
    /*Change all "ifs" code below so that it matches with the if statements above
    */
    
    else
     If num = 6;
    count<< " Get a War Hammer and bash goblins";
    
    else
     If num = 7;
    count<< " Head to dueling arena to train";
    
    else
     If num = 8;
    count<< " Grab Runes and mage guards";
    
    else
     If num = 9;
    count<< " Login on a noob account and pester everyone";
    
    else
     If num = 10;
    count<< " Hunt for Bob the Jagex Cat";
    
    else{
    return 0;
    }
    }

  5. #5
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    Sridar, your code has more compile errors than the op's =)

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    36
    That is cause i quit debugging his code after the the first if statement. I believe he understands his mistake now.

    The only errors are that he used "count" instead of "cout"
    and his "ifs" are in caps.

  7. #7
    Slave MadCow257's Avatar
    Join Date
    Jan 2005
    Posts
    735
    The only errors are that he used "count" instead of "cout"
    and his "ifs" are in caps.
    Not true,
    as one example
    "if num = 10;"
    this is wrong
    it should be
    "if (num == 10);"
    = is assignment
    == is comparison

  8. #8
    Registered User
    Join Date
    Sep 2004
    Posts
    36
    O sorry about that.

    *Should have worn my glasses*


    Normally i would catch those errors but today it slipped my eyes.
    Did u find any other errors MadCow?

  9. #9
    Rabite SirCrono6's Avatar
    Join Date
    Nov 2003
    Location
    California, US
    Posts
    269
    I did
    The while should be
    Code:
    while( num < 0 && num > 10 )
    He handles zero and ten in the if statements, and it needs to be &&.

    - SirCrono6
    From C to shining C++!

    Great graphics, sounds, algorithms, AI, pathfinding, visual effects, cutscenes, etc., etc. do NOT make a good game.
    - Bubba

    IDE and Compiler - Code::Blocks with MinGW
    Operating System - Windows XP Professional x64 Edition

  10. #10
    Registered User
    Join Date
    Dec 2004
    Posts
    5
    I keep getting psudocode mixed up with the real code and i don't see it need someone elses eye to catch them. Thanks for your help it has been a while since i did any of this i completely forgot about case statments. The Dev-C++ seems to only load the program for 1 second
    Last edited by Yoda Sabre; 04-09-2005 at 01:44 AM.

  11. #11
    Registered User
    Join Date
    Apr 2003
    Posts
    2,662
    Quote Originally Posted by Sridar
    This is ur debugged code.
    (snipped a listing of the entire program)
    Sridar, your code has more compile errors than the op's =)
    Quote Originally Posted by Sridar
    That is cause i quit debugging his code after the the first if statement.
    Well, then what about these includes:
    Code:
    #include <iostream>
    #include <stdio.h>
    #include <conio.h>
    #include <time.h>
    #include <stdlib.h>
    Do those comply with the C++ standard?

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21