whats wrong with my if statements

This is a discussion on whats wrong with my if statements within the C++ Programming forums, part of the General Programming Boards category; whats wrong with my if statements? #include <iostream.h> #include <time.h> #include <stdlib.h> #include <string.h> void main() { srand(time(NULL)); int punch ...

  1. #1
    Registered User
    Join Date
    Nov 2001
    Posts
    255

    whats wrong with my if statements

    whats wrong with my if statements?



    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>
    #include <string.h>
    void main()
    {
    srand(time(NULL));
    int punch = rand() % (5-1+1);
    int kick = rand() % (10 - 1 + 1);
    int kiblast = rand() % (15-1+1);
    int pl = 100;
    int epl = 100;
    int yen;
    int answer;
    char goku[5] = "Goku";
    char krillyn[10] = "Krillyn";
    char piccolo[10] = "Piccolo";
    char gohan[6] = "Gohan";
    cout<<"Pick a character?\n";
    cout<<"1. "<<goku<<endl;
    cout<<"2. "<<gohan<<endl;
    cout<<"3. "<<krillyn<<endl;
    cout<<"4. "<<piccolo<<endl;
    cin>>answer;
    cin.get();
    if (answer == 1)
    {
    LOOP: cout<<"Main Menu\n";
    cout<<"You have selected "<<goku;
    cout<<"OPTIONS\n";
    cout<<"_________________\n";
    cout<<"1. Fight Enemy\n";
    cout<<"2. Buy Items\n";
    cout<<"3. Buy Moves\n";
    cout<<"4. Fight Boss\n";
    cout<<"5. Fusion\n";
    cout<<"6. Armor\n";
    cout<<"7. Spar\n";
    cout<<"8. Stats\n";
    int answer2;
    cin>>answer2;
    if (answer2 == 1)
    {
    //fight sequence
    do
    {
    int goku = 100;
    int enemy1 = 100;
    cout<<"Attack menu\n";
    cout<<"____________\n";
    cout<<"1. punch\n";
    cout<<"2. kick\n";
    cout<<"3. ki blast\n";

    int ans;
    cin.get();
    cin>>ans;
    if (ans == 1)
    {

    epl = epl - punch;

    cout<<"You "<<pl<<" enemy "<<epl<<endl;
    }
    int rands = rand() % (10 - 1 + 1);
    pl = pl - rands;
    cout << "You "<<pl<<" Enemy "<<epl<<endl;

    if (ans == 2)
    {
    epl = epl - kick;
    pl = pl - rands;
    cout<<"You "<<pl<<" enemy "<<epl<<endl;

    }
    else if (ans == 3)
    {
    epl = epl - kiblast;
    pl = pl - rands;
    cout<<"You "<<pl<<" enemy "<<epl<<endl;
    }

    while (pl > 0 && epl > 0);
    }
    if (answer2== 2);
    LOOP2:{
    cout<<"1. space pod\n";
    cout<<"2. go back to main menu\n";
    int answer3;
    cin.get();
    cin>>answer3;
    if (answer3 == 1)
    {
    cout<<"do you have have 500¥?\n";
    char respond[4];
    cin.get(respond,4);
    cin.get();
    if ((strcmp(respond, "yes")==0))
    {
    cout<<"good job will that be all?\n";
    char respond2[5];
    cin.get(respond2,5);
    cin.get();
    if ((strcmp(respond2,"yes")==0))
    {
    goto LOOP;
    }
    if ((strcmp(respond2,"no")==0))
    {
    goto LOOP2;
    }
    }
    else if ((strcmp(respond,"no")==0))
    {
    goto LOOP2;
    }
    }
    if (answer3 == 2)
    {
    goto LOOP;
    }
    }
    }
    }






    }




    --------------------Configuration: funC++version - Win32 Debug--------------------
    Compiling...
    funC++version.cpp
    C:\Windows\Desktop\c++\funC++version.cpp(85) : error C2059: syntax error : 'if'
    Error executing cl.exe.

    funC++version.obj - 1 error(s), 0 warning(s)
    hooch

  2. #2
    Registered User
    Join Date
    Dec 2001
    Posts
    421
    1) put a '}' before the first 'while' statement
    2) remove the ';' from the end of the line 'if (answer2== 2);'
    3) get rid of the last '}'
    4) learn to comment your code
    5) use [ code ] tags when you are pasting code into this forum
    6) learn to use coding standards to avoid the problems you're having
    7) dont EVER use 'goto' statements.

    U.
    Quidquid latine dictum sit, altum sonatur.
    Whatever is said in Latin sounds profound.

  3. #3
    edwardtisdale
    Guest

    ifs

    Did you try putting all of the declarations (int answer,etc. ) at the top of the code?

  4. #4
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    hey thanx alot yea i do have troubles commetting code and everyone tells me not to use goto but i use it all the time lol how is it so bad??????
    hooch

  5. #5
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    Search the board about discussions that have taken place about goto.

  6. #6
    Unregistered
    Guest
    I've heard to never use goto statements, why exzactly?

  7. #7
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Other than making a programmer look inexperienced, nothing. The goto will not make your program unstable.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  8. #8
    Unregistered
    Guest
    The only problem w/ goto is that it makes the code hard to read.
    But it can be very helpful if you have no other choice but to use it.

  9. #9
    Señor Member
    Join Date
    Jan 2002
    Posts
    561
    I don't see any situation where you shold use goto (although I sometimes do because it takes less code). Where would oyu have to do so?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Unknown memory leak with linked lists...
    By RaDeuX in forum C Programming
    Replies: 6
    Last Post: 12-07-2008, 04:09 AM
  2. newbie question - if statements without conditions
    By c_h in forum C++ Programming
    Replies: 2
    Last Post: 07-18-2008, 11:42 AM
  3. Efficiency of case statements
    By Yasir_Malik in forum C Programming
    Replies: 26
    Last Post: 05-23-2006, 12:36 PM
  4. God
    By datainjector in forum A Brief History of Cprogramming.com
    Replies: 746
    Last Post: 12-22-2002, 12:01 PM
  5. Shorten Statements are WRONG?!
    By RoD in forum C++ Programming
    Replies: 29
    Last Post: 11-01-2002, 06:05 AM

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