i have an error in this code help?

This is a discussion on i have an error in this code help? within the C++ Programming forums, part of the General Programming Boards category; #include <iostream.h> #include <time.h> #include <stdlib.h> #include <string.h> void main() { srand = (time(NULL));/*this is the line the compiler points ...

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

    i have an error in this code help?

    #include <iostream.h>
    #include <time.h>
    #include <stdlib.h>
    #include <string.h>
    void main()
    {
    srand = (time(NULL));/*this is the line the compiler points to for the error*/
    int pl;
    int epl;
    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";
    int punch = rand() % (5-1+1);
    int kick = rand() % (10 - 1 + 1);
    int kiblast = rand() % (15-1+1);
    int ans;
    cin.get();
    cin>>ans;
    if (ans == 1)
    {
    epl = epl - punch;
    pl = 100;
    cout<<"You "<<pl<<" enemy "<<epl<<endl;
    }
    int rands = rand() % (10 - 1 + 1);
    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(7) : error C2659: '=' : overloaded function as left operand
    Error executing cl.exe.

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

  2. #2
    Registered User
    Join Date
    Jan 2002
    Posts
    552
    srand(time(NULL));

  3. #3
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    argh lol i should of known that oh well im no pro yet so it works right? and i kno how to make like .txt or .dat files or w/e but how do i make a .exe file im confused on that and im confused onhow do read datafrom a file?
    hooch

  4. #4
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    ick.. too many gotos

  5. #5
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    wats wrong with goto's?
    hooch

  6. #6
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    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

  7. #7
    ¡Amo fútbol!
    Join Date
    Dec 2001
    Posts
    2,136
    Just out of curiousity, doesn't cin.get return a char, not an int? If I am right, you have to do if (ans=='1') and the same with the rest

  8. #8
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    do u mean like this and if so this didnt work????



    #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;
    }
    }
    }
    }






    }
    hooch

  9. #9
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    also....

    int main (void)

    not void main()

    and gotos are the scum of programming - nearly as bad as system calls
    Monday - what a way to spend a seventh of your life

  10. #10
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    what is so bad about gotos? and i dun understand y would u i go
    int main(void)


    ????? but whats wrong with my if statements?
    hooch

  11. #11
    Hamster without a wheel iain's Avatar
    Join Date
    Aug 2001
    Posts
    1,385
    goto - you can read the faq - they are considered bad programmoing practice

    it is int main (void) regardless of which books, friends or teachers tekk you otherwise

    the return return value returns a value to the calling function or in the case of main to the os - it does return a value which is why it should be initialized as int - as no params arte passed you mark it int main(void)

    thats the way it is and the way professional programmers do it
    Monday - what a way to spend a seventh of your life

  12. #12
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Goto is an absolute, structure-breaking jump that can easily lead to spaghetti code...

  13. #13
    Registered User
    Join Date
    Nov 2001
    Posts
    255
    ok ill read the goto thing but whats wrong with my if statements tahts it giving me errors
    hooch

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extended ASCII Characters in an RTF Control
    By JustMax in forum C Programming
    Replies: 18
    Last Post: 04-03-2009, 09:20 PM
  2. Enforcing Machine Code Restrictions?
    By SMurf in forum Tech Board
    Replies: 21
    Last Post: 03-30-2009, 08:34 AM
  3. Obfuscated Code Contest
    By Stack Overflow in forum Contests Board
    Replies: 51
    Last Post: 01-21-2005, 04:17 PM
  4. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM
  5. Replies: 0
    Last Post: 02-21-2002, 06:05 PM

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