Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


C++, "jumping" on a else?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Chase Payne
Grandmaster Cheater
Reputation: 1

Joined: 20 Mar 2008
Posts: 533

PostPosted: Thu Aug 20, 2009 3:36 pm    Post subject: C++, "jumping" on a else? Reply with quote

Code:
#include "stdafx.h"
#include <iostream>
#include "Chasestest.h"
int main()
{
using namespace std;
cout << "Please enter your number: ";
cin >> x;
cout << "Good, now please enter the second number: ";
shorten();

}
void shorten()
{
using namespace std;
int y;
cin >> y;
int total;
total = x + y;
if (total == 42)
cout << " You have discovered the meaning of life!\n" << x + y;
else if (total <= 12)
cout << "\nWhy enter in such a low number\?\n";
else
cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
orange();
}


IS there anyway for me to only make it go to orange ONLY if the "Else" is triggered?
Back to top
View user's profile Send private message
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Thu Aug 20, 2009 3:39 pm    Post subject: Reply with quote

yeah, use brackets { }.

Code:
if (total == 42)
{
  cout << " You have discovered the meaning of life!\n" << x + y;
}
else if (total <= 12)
{
  cout << "\nWhy enter in such a low number\?\n";
}
else
{
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
}
Back to top
View user's profile Send private message
Chase Payne
Grandmaster Cheater
Reputation: 1

Joined: 20 Mar 2008
Posts: 533

PostPosted: Thu Aug 20, 2009 3:42 pm    Post subject: Reply with quote

DanielG wrote:
yeah, use brackets { }.

Code:
if (total == 42)
{
  cout << " You have discovered the meaning of life!\n" << x + y;
}
else if (total <= 12)
{
  cout << "\nWhy enter in such a low number\?\n";
}
else
{
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
}

I get a compiler error after that?
Back to top
View user's profile Send private message
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Thu Aug 20, 2009 3:44 pm    Post subject: Reply with quote

well post whole code and compiler error.
Back to top
View user's profile Send private message
Chase Payne
Grandmaster Cheater
Reputation: 1

Joined: 20 Mar 2008
Posts: 533

PostPosted: Thu Aug 20, 2009 3:45 pm    Post subject: Reply with quote

Code:

#include "stdafx.h"
#include <iostream>
#include "Chasestest.h"
int main()
{
   using namespace std;
   cout << "Please enter your number: ";
   cin >> x;
   cout << "Good, now please enter the second number: ";
   shorten();

}
void shorten()
{
    using namespace std;
   int y;
   cin >> y;
   int total;
   total = x + y;

if (total == 42)
{
cout << " You have discovered the meaning of life!\n" << x + y;
}
else if (total <= 12)
{
cout << "\nWhy enter in such a low number\?\n";
}

else
{
cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
orange();
}


1>------ Build started: Project: UNique, Configuration: Debug Win32 ------
1>Compiling...
1>UNique.cpp
1>c:\users\chase\documents\visual studio 2008\projects\unique\unique\unique.cpp(36) : fatal error C1075: end of file found before the left brace '{' at 'c:\users\chase\documents\visual studio 2008\projects\unique\unique\unique.cpp(15)' was matched
1>Build log was saved at "file://c:\Users\Chase\Documents\Visual Studio 2008\Projects\UNique\UNique\Debug\BuildLog.htm"
1>UNique - 1 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========


I can't see anything wrong with the brackets.
Back to top
View user's profile Send private message
DanielG
Expert Cheater
Reputation: 1

Joined: 13 May 2009
Posts: 130
Location: The Netherlands

PostPosted: Thu Aug 20, 2009 3:47 pm    Post subject: Reply with quote

you forgot the last bracket.

Code:
#include "stdafx.h"
#include <iostream>
#include "Chasestest.h"
int main()
{
   using namespace std;
   cout << "Please enter your number: ";
   cin >> x;
   cout << "Good, now please enter the second number: ";
   shorten();

}
void shorten()
{
    using namespace std;
   int y;
   cin >> y;
   int total;
   total = x + y;

  if (total == 42)
  {
    cout << " You have discovered the meaning of life!\n" << x + y;
  }
  else if (total <= 12)
  {
    cout << "\nWhy enter in such a low number\?\n";
  } 
  else
  {
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
  }
}


ps. use indentation, you'll notice it when the brackets don't line up. for every opening bracket there must be a closing one.


Last edited by DanielG on Thu Aug 20, 2009 3:48 pm; edited 1 time in total
Back to top
View user's profile Send private message
Chase Payne
Grandmaster Cheater
Reputation: 1

Joined: 20 Mar 2008
Posts: 533

PostPosted: Thu Aug 20, 2009 3:48 pm    Post subject: Reply with quote

DanielG wrote:
you forgot the last bracket.

Code:
#include "stdafx.h"
#include <iostream>
#include "Chasestest.h"
int main()
{
   using namespace std;
   cout << "Please enter your number: ";
   cin >> x;
   cout << "Good, now please enter the second number: ";
   shorten();

}
void shorten()
{
    using namespace std;
   int y;
   cin >> y;
   int total;
   total = x + y;

  if (total == 42)
  {
    cout << " You have discovered the meaning of life!\n" << x + y;
  }
  else if (total <= 12)
  {
    cout << "\nWhy enter in such a low number\?\n";
  } 
  else
  {
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
  }
}

Double brackets? hmm, looks like i need to read more on c++ lol
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Thu Aug 20, 2009 4:02 pm    Post subject: Reply with quote

note if it's only one line you can leave out the brackets :

Code:
  if (total == 42)
  {
    cout << " You have discovered the meaning of life!\n" << x + y;
  }
  else if (total <= 12)
  {
    cout << "\nWhy enter in such a low number\?\n";
  } 
  else
  {
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
  }


could be :

Code:
  if (total == 42)
    cout << " You have discovered the meaning of life!\n" << x + y;
  else if (total <= 12)
    cout << "\nWhy enter in such a low number\?\n";
  else
  {
  cout << "\n You don't know the meaning of life? It's certainly not:\t\t\t" << total;
  orange();
  }
Back to top
View user's profile Send private message
Flyte
Peanuts!!!!
Reputation: 6

Joined: 19 Apr 2006
Posts: 1887
Location: Canada

PostPosted: Thu Aug 20, 2009 8:39 pm    Post subject: Reply with quote

Slugsnack wrote:
note if it's only one line you can leave out the brackets[/code]


1TBS or bust, in my opinion.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Fri Aug 21, 2009 11:53 am    Post subject: Reply with quote

i still hate K & R. i can only see it being useful for people with tiny screens trying to squish as much on as possible. with a nice big screen allman is the best, in my opinion
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites