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 


How to add a Y/N to exit code?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
aasddsaadsasdasdasdassads
Expert Cheater
Reputation: 0

Joined: 28 Aug 2008
Posts: 161
Location: Singapore

PostPosted: Fri Mar 20, 2009 10:33 pm    Post subject: How to add a Y/N to exit code? Reply with quote

This is my code:
Code:
#include <cstdlib>
#include <iostream>
 
using namespace std;
 
int main()
{
    double num;
    double num2;
    char choice;
    for (;;){
     do {
    cout<<"Welcome to Raphael's Calculator\n";
    cout<<"Please choose an option by entering the number, press q to quit\n";
    cout<<"1 - Addition\n";
    cout<<"2 - Subtraction\n";
    cout<<"3 - Division\n";
    cout<<"4 - Multiplication\n";
    cout<<"5 - Help\n";
    cout<<"6 - About This Program\n";
    cout<<"7 - Updates to this program\n";
    cout<<"8 - Quit the program\n";       
         case '1':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be added\n";
                cin>>num2;
                cout<<num + num2;
                cout<<"\n";
                break;
           case '2':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be subtracted\n";
                cin>>num2;
                cout<<num - num2;
                cout<<"\n";
                break;
           case '3':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be divided\n";
                cin>>num2;
                cout<<num / num2;
                cout<<"\n";
                break;
           case '4':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be multiplied\n";
                cin>>num2;
                cout<<num * num2;
                cout<<"\n";
                break;
           case '5':
                cout<<"This is a simple calculator made by me - Raphael.\n";
                cout<<"To select an option, type the number next to the option and press enter\n";
                cout<<"E.G. for division, you would type 3 and press enter.\n";
                cout<<"\n";
                break;
           case '6':
                cout<<"Raphael's Calculator, made by Raphael Ong - Copyright 2009. :)\n";
                cout<<"Thanks for using my calculator\n";
                cout<<"Bye!!\n";
                cout<<"\n";
                break;
           case '7':
                cout<<"No Updates at the moment\n";
                cout<<"                 Sorry!\n";
                cout<<"\n";
                break;
           case '8':
                cout<<"Are you sure you want to quit";
               
                break;
         default:
                    cout<<"That is'nt an option!";
                   
                }
 
}
return 0;


}


How do i add a Y/N option to quit at the
Code:
case '8':
                cout<<"Are you sure you want to quit";

?
also, can you guys hep me check it for any errors. help would be greatly appreciated. BTW the above code has 10 errors! Can anyone help me to solved these probs. there seems to be a problem with the cases

this is my original code without Y/N but q to quit.

Code:
#include <cstdlib>
#include <iostream>
 
using namespace std;
 
int main()
{
    double num;
    double num2;
    char choice;
    for (;;){
     do {
    cout<<"Welcome to Raphael's Calculator\n";
    cout<<"Please choose an option by entering the number, press q to quit\n";
    cout<<"1 - Addition\n";
    cout<<"2 - Subtraction\n";
    cout<<"3 - Division\n";
    cout<<"4 - Multiplication\n";
    cout<<"5 - Help\n";
    cout<<"6 - About This Program\n";
    cout<<"7 - Updates to this program\n";
    cin>>choice;
    } while ( choice < '1' || choice > '7' && choice != 'q');
    if (choice == 'q') break;
    switch (choice) {
           case '1':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be added\n";
                cin>>num2;
                cout<<num + num2;
                cout<<"\n";
                break;
           case '2':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be subtracted\n";
                cin>>num2;
                cout<<num - num2;
                cout<<"\n";
                break;
           case '3':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be divided\n";
                cin>>num2;
                cout<<num / num2;
                cout<<"\n";
                break;
           case '4':
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be multiplied\n";
                cin>>num2;
                cout<<num * num2;
                cout<<"\n";
                break;
           case '5':
                cout<<"This is a simple calculator made by me - Raphael.\n";
                cout<<"To select an option, type the number next to the option and press enter\n";
                cout<<"E.G. for division, you would type 3 and press enter.\n";
                cout<<"\n";
                break;
           case '6':
                cout<<"Raphael's Calculator, made by Raphael Ong - Copyright 2009. :)\n";
                cout<<"Thanks for using my calculator\n";
                cout<<"Bye!!\n";
                cout<<"\n";
                break;
           case '7':
                cout<<"No Updates at the moment\n";
                cout<<"                 Sorry!\n";
                cout<<"\n";
                break;
           default:
                    cout<<"That is not an option";
                   
                }
 
}
return 0;


}


Attached are the two projects rared (broken and original)



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.



Last edited by aasddsaadsasdasdasdassads on Fri Mar 20, 2009 11:11 pm; edited 1 time in total
Back to top
View user's profile Send private message MSN Messenger
slippppppppp
Grandmaster Cheater
Reputation: 0

Joined: 08 Aug 2006
Posts: 929

PostPosted: Fri Mar 20, 2009 10:39 pm    Post subject: Reply with quote

use std::cin. But use a char parameter instead of an integer, then use strcmp
Back to top
View user's profile Send private message AIM Address MSN Messenger
talkerzero
Grandmaster Cheater
Reputation: 1

Joined: 24 Jul 2008
Posts: 560
Location: California

PostPosted: Fri Mar 20, 2009 10:52 pm    Post subject: Reply with quote

Looking at your code, you haven't even allowed the user the select an option from # 1-8, which you can do with std::cin..
Back to top
View user's profile Send private message Visit poster's website
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Fri Mar 20, 2009 10:57 pm    Post subject: Reply with quote

Yeah i was gunna say lol
also is that you state cases?

i tried to compile that and gave errors (illegal case's)

_________________
Back to top
View user's profile Send private message
aasddsaadsasdasdasdassads
Expert Cheater
Reputation: 0

Joined: 28 Aug 2008
Posts: 161
Location: Singapore

PostPosted: Fri Mar 20, 2009 11:13 pm    Post subject: code Reply with quote

std::cin? someone just insert it in my code pls. i am a newb. or at least just tell me where to edit. tks. if you dint know i edited the post. brb. im going to eat my lunch nw.
Back to top
View user's profile Send private message MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Fri Mar 20, 2009 11:14 pm    Post subject: Reply with quote

lol lunch? I just had a snack before bad
anyways, im going to post a code here in a sec
brb

_________________
Back to top
View user's profile Send private message
V.A.C.H.
Newbie cheater
Reputation: 0

Joined: 05 Dec 2008
Posts: 22
Location: Just arrived at mars

PostPosted: Fri Mar 20, 2009 11:24 pm    Post subject: Reply with quote

Switch cases:
Code:
int a;
cout<<"Enter # 1-8" << endl;
cin>>a;
switch(a)
{
case 1:
cout<<"hi";
break;
case 2:
cout<<"bye";
break;
case 3:
cout<<"lets get the partey started";
break;
//so on
}

*wrote this while he edited -.-

to get your y/n
use if statement:
Code:
char answer;
cout<<"y/n?";
cin>>answer;
if (answer = 'y') {
return 0;
}
if (answer = 'n') {
return main();
}

_________________
V. Visual Basic
A. Assembly
C. C++/C
H. Hex
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Fri Mar 20, 2009 11:40 pm    Post subject: Reply with quote

Code:
#include <cstdlib>
#include <iostream>
 #include "Windows.h"

using namespace std;
 
int main()
{
    double num;
    double num2;
    char choice;

   // ~~~~~~~~~Extras~~~~~~~~~~~~~~
    SetConsoleTitle("Raphael's Calculator"); //makes the window title "Raphael's Calculator"
   HANDLE rofl=GetStdHandle(STD_OUTPUT_HANDLE); // makes the text red
   SetConsoleTextAttribute(rofl, FOREGROUND_RED); // makes the text red
   //~~~~~~~~~Extras~~~~~~~~~~~~

   HWND yourhandle = GetConsoleWindow();
   cout<<"Welcome to Raphael's Calculator\n";
 
   
   for(;;Sleep(25))
   {
    int input; // input is used in the main menu (choosing 1-8)
   char lolz; // lolz is used in case 8
    cout<<"\n-------------------------------------------\n";
    cout<<"Please choose an option by entering the number, press q to quit\n";
    cout<<"1 - Addition\n";
    cout<<"2 - Subtraction\n";
    cout<<"3 - Division\n";
    cout<<"4 - Multiplication\n";
    cout<<"5 - Help\n";
    cout<<"6 - About This Program\n";
    cout<<"7 - Updates to this program\n";
    cout<<"8 - Quit the program\n";   
   cin >> choice;

   
switch (choice)

{
        case (1):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be added\n";
                cin>>num2;
                cout<< "The answer is" <<(num + num2);
                cout<<"\n";
                break;
   
       case (2):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be subtracted\n";
                cin>>num2;
                cout<<"The answer is" << (num - num2);
                cout<<"\n";
                break;

       case (3):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be divided\n";
                cin>>num2;
                cout<<"The answer is" << (num / num2);
                cout<<"\n";
               Sleep(1000);
                break;

       case (4):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be multiplied\n";
                cin>>num2;
                cout<<"The answer is" << (num * num2);
                cout<<"\n";
               Sleep(1000);
                break;

       case (5):
                cout<<"This is a simple calculator made by me - Raphael.\n";
                cout<<"To select an option, type the number next to the option and press enter\n";
                cout<<"E.G. for division, you would type 3 and press enter.\n";
                cout<<"\n";
            Sleep(1000);
                break;

       case (6):
                cout<<"Raphael's Calculator, made by Raphael Ong - Copyright 2009. :)\n";
                cout<<"Thanks for using my calculator\n";
                cout<<"\n";
               Sleep(1000);
                break;

       case (7):
                cout<<"No Updates at the moment\n";
                cout<<"                 Sorry!\n";
                cout<<"\n";
               Sleep(1000);
                break;

       case (8):
                cout<<"Are you sure you want to quit? (Yes=y No=n)";
loop:
            cin >> lolz;

         if(lolz == 'y')
            PostMessage(yourhandle, WM_CLOSE , 0 , 0);
         else if(lolz == 'n')
         break;

         else cout << "Choose y for yes, or n for no" << endl;
         goto loop;
         
       default:
                    cout<<"That isn't an option!";
                   
                }
    }

   


}





FINAL EDIT::



100% fixed now


Another Edit: I also added a few comments to explain it a little

_________________


Last edited by manc on Sat Mar 21, 2009 12:12 am; edited 2 times in total
Back to top
View user's profile Send private message
aasddsaadsasdasdasdassads
Expert Cheater
Reputation: 0

Joined: 28 Aug 2008
Posts: 161
Location: Singapore

PostPosted: Fri Mar 20, 2009 11:50 pm    Post subject: Reply with quote

manc wrote:
Code:
#include <cstdlib>
#include <iostream>
 #include "Windows.h"

using namespace std;
 
int main()
{
    double num;
    double num2;
    char choice;

   // ~~~~~~~~~Extras~~~~~~~~~~~~~~
    SetConsoleTitle("Raphael's Calculator");
   HANDLE rofl=GetStdHandle(STD_OUTPUT_HANDLE);
   SetConsoleTextAttribute(rofl, FOREGROUND_RED);
   //~~~~~~~~~Extras~~~~~~~~~~~~

   HWND yourhandle = GetConsoleWindow();
   cout<<"Welcome to Raphael's Calculator\n";
 
   
   for(;;Sleep(25))
   {
    int input;
   char lolz;
    cout<<"\n-------------------------------------------\n";
    cout<<"Please choose an option by entering the number, press q to quit\n";
    cout<<"1 - Addition\n";
    cout<<"2 - Subtraction\n";
    cout<<"3 - Division\n";
    cout<<"4 - Multiplication\n";
    cout<<"5 - Help\n";
    cout<<"6 - About This Program\n";
    cout<<"7 - Updates to this program\n";
    cout<<"8 - Quit the program\n";   
   cin >> input;

   
switch (input)

{
        case (1):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be added\n";
                cin>>num2;
                cout<< "The answer is" <<(num + num2);
                cout<<"\n";
                break;
   
       case (2):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another number to be subtracted\n";
                cin>>num2;
                cout<<"The answer is" << (num - num2);
                cout<<"\n";
                break;

       case (3):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be divided\n";
                cin>>num2;
                cout<<"The answer is" << (num / num2);
                cout<<"\n";
               Sleep(1000);
                break;

       case (4):
                cout<<"Please enter a number\n";
                cin>>num;
                cout<<"Another one to be multiplied\n";
                cin>>num2;
                cout<<"The answer is" << (num * num2);
                cout<<"\n";
               Sleep(1000);
                break;

       case (5):
                cout<<"This is a simple calculator made by me - Raphael.\n";
                cout<<"To select an option, type the number next to the option and press enter\n";
                cout<<"E.G. for division, you would type 3 and press enter.\n";
                cout<<"\n";
            Sleep(1000);
                break;

       case (6):
                cout<<"Raphael's Calculator, made by Raphael Ong - Copyright 2009. :)\n";
                cout<<"Thanks for using my calculator\n";
                cout<<"\n";
               Sleep(1000);
                break;

       case (7):
                cout<<"No Updates at the moment\n";
                cout<<"                 Sorry!\n";
                cout<<"\n";
               Sleep(1000);
                break;

       case (8):
                cout<<"Are you sure you want to quit? (Yes=9 No=0)";
loop:
            cin >> lolz;

         if(lolz == 'y')
            PostMessage(yourhandle, WM_CLOSE , 0 , 0);
         else if(lolz == 'n')
         break;

         else cout << "choose y for yes or n for no" << endl;
         goto loop;
         
       default:
                    cout<<"That isn't an option!";
                   
                }
    }

   


}





whats with the lolz and rofl, does it do any good. wow it works after i deleted the extras part. but how do i make the extras work? and i edited your original code to this
Code:
case (8):
                cout<<"Are you sure you want to quit? (Yes=y No=n)";
loop:
            cin >> lolz;

         if(lolz == 'y')
            PostMessage(yourhandle, WM_CLOSE , 0 , 0);
         else if(lolz == 'n')
         break;

         else cout << "choose y for yes or n for no" << endl;
         goto loop;
[/code]
Back to top
View user's profile Send private message MSN Messenger
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Mar 21, 2009 12:02 am    Post subject: Reply with quote

use the very last one i posted ( i updated it)



then

1] right click your whole project
2] go to properties
3] Configuration Properties-->General
4] Make sure its set to multi-byte
5] hit ok and re-compile



The Extension 'rar' was deactivated by an board admin, therefore this Attachment is not displayed.


_________________
Back to top
View user's profile Send private message
blackmorpheus
Expert Cheater
Reputation: 0

Joined: 05 Apr 2008
Posts: 159

PostPosted: Sat Mar 21, 2009 7:09 am    Post subject: Reply with quote

Pro Leet Paint Skills Very Happy
Back to top
View user's profile Send private message
aasddsaadsasdasdasdassads
Expert Cheater
Reputation: 0

Joined: 28 Aug 2008
Posts: 161
Location: Singapore

PostPosted: Sat Mar 21, 2009 8:46 am    Post subject: now this comes out Reply with quote

now this comes out.


Picture1.png
 Description:
 Filesize:  90.37 KB
 Viewed:  7636 Time(s)

Picture1.png


Back to top
View user's profile Send private message MSN Messenger
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Mar 21, 2009 11:59 am    Post subject: Reply with quote

did you really use a goto? wtf.

also SWITCH IN A FOR LOOP... why god.


String class would like a word with you... (or strcmp)
Back to top
View user's profile Send private message
manc
Grandmaster Cheater
Reputation: 1

Joined: 16 Jun 2006
Posts: 551

PostPosted: Sat Mar 21, 2009 12:29 pm    Post subject: Reply with quote

slovach wrote:
why god

Inebriated + sucks at programming to begin with
Cool

_________________
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