do-while error

This is a discussion on do-while error within the C++ Programming forums, part of the General Programming Boards category; When I try to compile my code, it says "do statement must have while in function main() ". I do ...

  1. #1
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176

    do-while error

    When I try to compile my code, it says "do statement must have while in function main()
    ". I do have while. What is wrong?
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    while your at it don't forget to you know, show us the code....

    just in case u didn't know:

    do
    {
    program junk
    }

    while(some condition)

    /* edit: Dammit i hate same-second posts....*/

  3. #3
    booyakasha
    Join Date
    Nov 2002
    Posts
    208
    post the code of the loop

  4. #4
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Here it is:
    Code:
    //before I include all the stuff and declare integers
    do
    {
    //my code
    }
    while (foe_health>0 && health>0);
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  5. #5
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    This should work just fine

    [edit]
    Post more of your code

  6. #6
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    try putting the parentheses against the while not this far away, just a guess.

    SHOULD work tho.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Doesn't matter

  8. #8
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    You are forgetting the error, do statement must have while in function main()
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    As i said, post more code, like where its standing in your
    source

  10. #10
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    post the whole main

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    ^ you reached 1400, nice job

  12. #12
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    heh, i stopped paying attention to my PC a long time ago...


    *waits for code so he and others can post at the same time some more*

  13. #13
    fuh
    fuh is offline
    Attack hamster fuh's Avatar
    Join Date
    Dec 2002
    Posts
    176
    Okay, but it is out of order.
    Code:
    					#include <windows.h>//1
                                  #include <conio.h> //2
    					#include <stdlib.h>//3
                                  #include <iostream.h>//4
                                  int main() //5
                                  {//6
                                  int health;//7
                                  int foe_health;//8
                                  int damage;//9
                                  int foe_damage;//10
                                  int attack;//11
                                  int l;//12
                                  cout<<"How much health should you and the opponent have? ";//13
                                  cin>>health;//14
                                  foe_health=health;//14
                                  cout<<"\nThe fight begins!\n";//15
                                  do//16
                                  { //16
                                  {//17
                                  randomize();//18
                                  cout<<"Press 1 for punch, 2 for kick, 3 for blast, and 4 for defend.\n";//19
                                  cin>>attack;//20
                                  if (attack==1)//21
                                  {//22
                                  damage=rand () % 6;//23
                                  foe_damage=rand () % 7;//24
                                  cout<<"You punched and did "<<damage<<" damage and the opponent did "<<foe_damage<<" damage.";//25
                                  foe_health-=damage;//26
                                  health-=foe_damage;//27
                                  }//28
                                  if (attack==2)//29
                                  {//30
                                  damage=rand () % 11;//31
                                  foe_damage=rand () % 13;//32
                                  cout<<"You kicked and did "<<damage<<" damage and the opponent did "<<foe_damage<<" damage.";//33
                                  foe_health-=damage;//34
                                  health-=foe_damage;//35
                                  }//36
                                  if (attack==3)//37
                                  {//38
                                  damage=rand () % 20;//39
                                  foe_damage=rand () % 23;//40
                                  cout<<"You blasted and did "<<damage<<" damage and the opponent did "<<foe_damage<<" damage.";//41
                                  foe_health-=damage;//42
                                  health-=foe_damage;//43
                                  }//44
    					if (attack==42)//45
    					{//46
    					damage=foe_health;//47
    					cout<<"You found the destroy move. To do it again, enter 4 at the attack screen. You did "<<foe_health<<" damage\n";//48
    					foe_health-=damage;//49
    					health-=foe_damage;//50
                                  }//51
                                  {//52
                                  if (attack==4)//53
                                  {//54
                                  damage=rand () %20;//55
                                  foe_damage-=damage;//56
    					health-=foe_damage;//57
    					}//58
    					clrscr();//59
    					//60
    					cout<<"Your Health: "<<health<<"\nEnemy Health: "<<foe_health<<"\n";//61
                                  }//62
    					}//63
                                  while (health>0 && foe_health>0);//64
    					if (foe_health<1)//65
    					//66
    					{//67
    					cout<<"YOU WIN";//68 
    					getch();//69
    					}//70
    					//71
    					if (health<1)//72
    					//73
    					{//74
    					cout<<"YOU LOSE ";//75
    					getch();//76
    					}//77
    					//78
    					}//79
                                  return 0;//80
    					}//81
    Last edited by fuh; 12-20-2002 at 03:01 PM.
    Stupid things pop singers say

    "I get to go to lots of overseas places, like Canada."
    - Britney Spears

    "I love what you've done with the place!"
    -Jessica Simpson upon meeting the Secretary of Interior during tour of the White House

  14. #14
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    i think u may have

    do
    {
    { as opposed to

    do
    {


    but i may be wrong, hard to read that.

  15. #15
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    That's the worst code EVER posted

    [edit]

    You're using 1 { too much at the beginning and 1 } to much at
    the end

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 12:10 AM

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