The McLeodGaming forums were permanently closed on April 30th, 2020. You are currently viewing a read-only archive.
View unanswered posts | View active topics It is currently Fri May 15, 2020 5:51 am



 [ 8 posts ] 
Do while loop won't work! 
Author Message
User avatar

Joined: Wed Mar 09, 2011 2:49 pm
Posts: 457
Gender: Male
Currently Playing: Ball Breaker with your sister. it's a real game...
I decided to make a small simple game where you do math..... After I got it to work I decided to have a little fun for the rare ocassion that someone would type in a value over 100. I used void functions since they're suppose to be easiest to work with. All I want to do is make the tiny piece on the bottom work which is a which statement. Can someone explain what I'm doing wrong? :-_-:


Code:
#include <iostream>
using namespace std;


void crazy ()  // void function 1
   {cout<< "You're crazy";} // end of void function 1
void not_smart() //void function 2
   { int age; cout<< "what is your age? \n"; 
     cin>> age;
     if (age > 13) cout<<"you're an idiot";} // end of void function 2
int main()
/////////////////////////////////////////////////////////////



// The program to run
{
   int Age;
   int *Zega;
   Zega = &Age;
   // Variables


cout<< "Sindy age is 15 + 15 -5 \n"<<
      "John age is 10 + ten + 5 + 10 - two - 8 \n"<<
      "laurent age is 20 + 5 -25 + one*25 \n";   
cout<< "What are Sindy, John, and laurent ages?";
 
do                     
   {cin>> Age;
    if (*Zega < 25){cout<<endl <<"Too young";}
   else if (*Zega > 25){cout<< endl<< "Very close";}
   else if (*Zega = 25 ) {cout<<"you won now get lost \n"; return 0; }
} while (*Zega != 25);








while (*Zega > 100)
{cout<<" please pick your stupid level :)";

switch (*Zega)   
   {   
    case 'a1': crazy(); break;
   case 'a2': not_smart(); break;
   defualt: cout<<" error you idiot";
   }
}

return 0;
}                         // END OF PROGRAM

_________________
As cold and empty as space. This is who I am.


Tue Apr 10, 2012 3:35 pm
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
the while conditional at the start of that last segment does not have a corresponding do statement
i'd explain how they're supposed to work but you have a correctly set up one in the section above it

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Tue Apr 10, 2012 8:44 pm
WWW
User avatar

Joined: Sat Aug 16, 2008 8:38 am
Posts: 6670
Location: Darkest Antartica
Country: Pakistan (pk)
Gender: Male
Skype: Thaiberium
Currently Playing: The Game
Tid wrote:
the while conditional at the start of that last segment does not have a corresponding do statement
i'd explain how they're supposed to work but you have a correctly set up one in the section above it

Code:
while (*Zega > 100)
{cout<<" please pick your stupid level :)";

switch (*Zega)   
   {   
    case 'a1': crazy(); break;
   case 'a2': not_smart(); break;
   defualt: cout<<" error you idiot";
   }
}

_________________
Image


Wed Apr 11, 2012 4:50 am
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
oh, after running the code through my compiler i get what you're saying now. I was under the impression you were getting actual build errors, and i was looking for an issue with your syntax.

the issue is that it can't leave that first do while loop until *Zega == 25
see, to fulfill that second while conditional, it's gotta be greater than 100, but it can't get to that second while conditional until it leaves your first loop (and like i said, it can't do that till *Zega == 25, which is most definitely not > 100).
The issue is not with your code, or else you'd be getting a build error. It's just logically impossible for the program to reach the while conditional and still have *Zega > 100. Just put the >100 stuff in another else if.

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Apr 11, 2012 5:02 am
WWW
User avatar

Joined: Wed Mar 09, 2011 2:49 pm
Posts: 457
Gender: Male
Currently Playing: Ball Breaker with your sister. it's a real game...
It's still not working. I think I may have missed something about loops. I put the while statement stuff in with a else if and even if I type a value over 100 it still reads "very close"

Thanks for the help I'm greatful. I need to learn what I missed about do while loops because it isn't working the way I want.
Code:
using namespace std;


void crazy ()  // void function 1
   {cout<< "You're crazy";} // end of void function 1
void not_smart() //void function 2
   { int age; cout<< "what is your age? \n"; 
     cin>> age;
     if (age > 13) cout<<"you're an idiot";} // end of void function 2
int main()
/////////////////////////////////////////////////////////////



// The program to run
{
   int Age;
   int *Zega;
   Zega = &Age;
   // Variables


cout<< "Sindy age is 15 + 15 -5 \n"<<
      "John age is 10 + ten + 5 + 10 - two - 8 \n"<<
      "laurent age is 20 + 5 -25 + one*25 \n";   
cout<< "What are Sindy, John, and laurent ages?";
 
do                     
   {cin>> Age;
    if (*Zega < 25){cout<<endl <<"Too young";}
   else if (*Zega > 25){cout<< endl<< "Very close";}
   else if (*Zega = 25 ) {cout<<"you won now get lost \n"; return 0; }

   else if (*Zega > 100)
{cout<<" please pick your stupid level \n"<<" type in a1 or a2 :)";

switch (*Zega)   
   {   
    case 'a1': crazy(); break;
   case 'a2': not_smart(); break;
   defualt: cout<<" error you idiot";
   }
}
   
   } while (*Zega != 25);


return 0;
}                         // END OF PROGRAM

_________________
As cold and empty as space. This is who I am.


Wed Apr 11, 2012 2:47 pm
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
it's probably not ever going to the else if (*Zega > 100) because it's doing the else if (*Zega > 25) first, you need to chuck an && *Zega < 100 in there.
But jesus, your indentation and whitespace formatting is so bad, there's honestly probably some nesting issue or typo somewhere in there. Lets restructure a bit, shall we? We use tabs, not space bars, to indent a line forward. We'll give close braces their own line so that we can clearly see how far they're indented and what open braces they correspond to. While we're at it, we'll throw in that logical AND change I mentioned.
Code:
#include <iostream>
using namespace std;


void crazy ()  // void function 1
   {cout<< "You're crazy";} // end of void function 1
void not_smart() //void function 2
   { int age; cout<< "what is your age? \n";
     cin>> age;
     if (age > 13) cout<<"you're an idiot";} // end of void function 2
int main()
/////////////////////////////////////////////////////////////



// The program to run
{
   int Age;
   int *Zega;
   Zega = &Age;
   // Variables


cout<< "Sindy age is 15 + 15 -5 \n"<<
      "John age is 10 + ten + 5 + 10 - two - 8 \n"<<
      "laurent age is 20 + 5 -25 + one*25 \n";   
cout<< "What are Sindy, John, and laurent ages?";

do                     
   {cin>> Age;
      if (*Zega < 25){cout<<endl <<"Too young";}
      else if (*Zega > 25 && *Zega < 100){cout<< endl<< "Very close";}
      else if (*Zega > 100){
         cout<<" please pick your stupid level \n"<<" type in a1 or a2 :)";
         switch (*Zega) {   
            case 'a1': crazy(); break;
            case 'a2': not_smart(); break;
            defualt: cout<<" error you idiot";
         }
      }
   } while (*Zega != 25);


return 0;
}


Running this through my compiler, I had no issues getting it to access any of your else if selections.

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Apr 11, 2012 3:59 pm
WWW
User avatar

Joined: Wed Mar 09, 2011 2:49 pm
Posts: 457
Gender: Male
Currently Playing: Ball Breaker with your sister. it's a real game...
YES! It works well almost..... There something wrong with my switch case but I can handle it.....hopefully. I've trouble you enough I must make this one work by myself. Thanks again

_________________
As cold and empty as space. This is who I am.


Wed Apr 11, 2012 5:02 pm
User avatar

Joined: Fri Jan 02, 2009 6:02 pm
Posts: 7283
Location: Australia
Country: Australia (au)
Gender: Male
MGN Username: Tid
Currently Playing: Deep™ The™ Game™
No problem, happy to help where I can. I noticed your Switch case was a bit broken, but you were using functions that aren't a part of this file, so I didn't look too far into it.

_________________
ImageImageImageImage
Ask me anything!!!
Special thanks to Steven for my beautiful Deep avatar! <3


Wed Apr 11, 2012 6:43 pm
WWW
Display posts from previous:  Sort by  
 [ 8 posts ] 

Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron
Powered by phpBB® Forum Software © phpBB Group
Designed by ST Software for PTF.