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 


my second C++

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

Joined: 11 Aug 2007
Posts: 314

PostPosted: Tue Apr 14, 2009 3:31 pm    Post subject: my second C++ Reply with quote

Heres my second code, it closes after the first selection. Any comments on it?

p.s Please dont get to advanced with it as i am a noob at C++
Code:

// My second program
// This program will kinda be like a calculator

#include <iostream>

using namespace std;

int main()
{
     // define variables
     float num1;   
     float num2;
     float total1;
     float total2;
     float total3;
     float num3;
     float multiply;
     float add;
     float divide;
     float selection;
     // What do I want to do?
     cout <<"What would you like to do?(add, divide, multiply)  ";
     cin>> selection;
     if (selection == multiply)
      {
              cout << "Please enter the first variable:  ";
              cin >> num1;
              cout << "Please enter the second variable:  ";
              total1 = num1 * num2;
              cout << "The pruduct is = "<< total1 << endl;
              cout << "please press anything to exit ";
              cin >> num3;
              }
     // enter data for the variables
    else if (selection == divide)
    {
     cout <<"Enter a value for the first variable:  ";
     cin >> num1;
     cout <<"Enter a value for the second variable:  ";
     cin >> num2;
     
     //  Add the two numbers together
     total2 = num1 / num2;
     
     // Display Results
     cout <<  "The answer is "<< total2 << endl;
     cout << "Please press any number or letter, then enter to exit.  ";
     cin >> num3;
     }
     
}

_________________
i loled hard at this
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Tue Apr 14, 2009 4:31 pm    Post subject: Reply with quote

This isn't even functional code...

(i'm editing my post so give me a minute)

1. Really, what is going on with the variables?

Most of them do absolutely nothing.

Code:
cin>> selection;
if (selection == multiply)


multiply is never initialized to anything, you'll crash here.



2. If by some miracle you made it past, you'll crash at:
Code:
total1 = num1 * num2;
num2 is never initialized to anything.

3. Crash at
Code:
else if (selection == divide)
divide is never initialized to anything.

4. Finally, you never return anything for main.



5. I assume this is basically what you were trying to do...

Code:
#include <iostream>
using namespace std;

int main()
{
   int selection;
   float num1;   
   float num2;

   cout << "What would you like to do? (1. add, 2. subtract, 3. multiply, 4. divide)";
   cin >> selection;
   cout << "Please enter two numbers:" << endl;
   switch(selection)
   {      
   case 1://add      
      cin >> num1 >> num2;
      cout << (num1 + num2);
      break;
   case 2://sub
      cin >> num1 >> num2;
      cout << (num1 - num2);
      break;
   case 3://mul
      cin >> num1 >> num2;
      cout << (num1 * num2);
      break;
   case 4://div
      cin >> num1 >> num2;
      cout << (num1 / num2);   
      break;
   default:
      cout << "What.";
      break;
   }
   return 0;
}


Last edited by hcavolsdsadgadsg on Tue Apr 14, 2009 5:03 pm; edited 1 time in total
Back to top
View user's profile Send private message
Caelestis
Expert Cheater
Reputation: 0

Joined: 03 May 2007
Posts: 153

PostPosted: Tue Apr 14, 2009 4:55 pm    Post subject: Reply with quote

What the hell is a float being compared to an enumeration for? (Oh wait I didn't read the variables.. do you even know what a float is?)

Anyway, its not good to just dump your crap here for analyzation. Keep going at the tutorial that you are doing please...

also.. you can declare that laundry list of floats like this:

float var1, var2, var3, var4;

if you want people to type "multiply" then you need a string of letters

#include <string>

string answer; //declare string

if(answer == "multiply") {code here}

I think you have many logical fallacies in your program. I recommend starting your education again with http://www.cplusplus.com/doc/tutorial/

Did you even try compiling it? My mind is boggled. Download VC++ express and learn how to compile programs...
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Tue Apr 14, 2009 6:43 pm    Post subject: Reply with quote

Wait... what?
Back to top
View user's profile Send private message
hacksign23
Master Cheater
Reputation: 0

Joined: 26 Nov 2006
Posts: 404

PostPosted: Wed Apr 15, 2009 11:59 pm    Post subject: Reply with quote

// My second program
// This program will kinda be like a calculator

#include <iostream>

using namespace std;

int main()
{
// define variables
float num1;
float num2;
float total1;
float total2;
float total3;
float num3;
float multiply;
float add;
float divide;
float selection;
// What do I want to do?
cout <<"What would you like to do?(add, divide, multiply) ";
cin>> selection;
if (selection == multiply)
{
cout << "Please enter the first variable: ";
cin >> num1;
cout << "Please enter the second variable: ";
total1 = num1 * num2;
cout << "The pruduct is = "<< total1 << endl;
cout << "please press anything to exit ";
cin >> num3;
}
// enter data for the variables
else if (selection == divide)
{
cout <<"Enter a value for the first variable: ";
cin >> num1;
cout <<"Enter a value for the second variable: ";
cin >> num2;

// Add the two numbers together
total2 = num1 / num2;

// Display Results
cout << "The answer is "<< total2 << endl;
cout << "Please press any number or letter, then enter to exit. ";
cin >> num3;
}

}

you used multiply as though it was a variable, but it's a string. Already said Neutral i have a variable solver I'm making. so many loops.

_________________
Back to top
View user's profile Send private message AIM Address
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