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++] #include <iostream> error - FIXED!

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

Joined: 27 Dec 2009
Posts: 100

PostPosted: Fri Feb 26, 2010 11:59 pm    Post subject: [C++] #include <iostream> error - FIXED! Reply with quote

Hi, I'm really new to C++, this is my 1st C++ application in the making so please don't be too hard on me. I am trying to make a basic calculator that multiplies, divides, adds and subtracts 2 numbers that the user inputs.

This is my source:
Code:
// BasicCalculator.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "<iostream>"

void main()
{
   for (char chrYN = 'Y'; chrYN == 'Y' || 'y')
   {
   system("CLS");

   system("TITLE Basic Calculator 1.0");
   system("COLOR 2");

   short sht1 = 0;
   short sht2 = 0;
   char chrOP = NULL;

   std::cout << "Hello and welcome to the Basic Calculator Version 1.0!" << endl;
   std::cout << "Please type in your first number." << endl;
   std::cin >> sht1;
   system("CLS");
   std::cout << "Please select one of the 4 operators below to use:" << endl;
   std::cout << " + (addition), - (subtraction), * (multiplication) or / (division)" <<endl;
   std::cin >> chrOP;
   system("CLS");
   std::cout << "Please type in your second number." << endl;
   std::cin >> sht2;
   system("CLS");
   
      switch (chrOP)
      {
         case '+':
            std::cout << sht1 + "+" + sht2 + "=" + sht1 + sht2 << endl;
            break;
         case '-':
            std::cout << sht1 + "-" + sht2 + "=" + sht2 - sht2 << endl;
            break;
         case '*':
            std::cout << sht1 + "*" + sht2 + "=" + sht2 * sht2 << endl;
            break;
         case '/':
            std::cout << sht1 + "/" + sht2 + "=" + sht2 / sht2 << endl;
            break;
         case default:
            std::cout << "Please choose one of the allowed operators." << endl;
            break;
      }
      std::cout << "Would you like to continue to calculate? (Y/N)" << endl;
      std::cin >> chrYN;
   }
   return 0;
}


and this is my error:
Code:
fatal error C1083: Cannot open include file: '<iostream>': Invalid argument



Thanks for your help!

I haven't got to test it out yet so I'm not sure if it works...


Last edited by TROLOLOLOLOLOLOLOLOLOLOLO on Mon Mar 01, 2010 8:03 pm; edited 3 times in total
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Feb 27, 2010 12:06 am    Post subject: Reply with quote

you use either <> or ""

<> is generally used for system includes and "" for your custom includes that you have defined yourself. in this case iostream counts as system
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Feb 27, 2010 12:11 am    Post subject: Reply with quote

Slugsnack wrote:
you use either <> or ""

<> is generally used for system includes and "" for your custom includes that you have defined yourself. in this case iostream counts as system


Thanks a lot Slugsnack! That fixed that issue, now onto debugging my buggy application Mad
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Feb 27, 2010 12:23 am    Post subject: Reply with quote

the contents of a for loop needs 2 semicolons and if your main is going to return an int then why not put that in its declaration
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Feb 27, 2010 12:36 am    Post subject: Reply with quote

Slugsnack wrote:
the contents of a for loop needs 2 semicolons and if your main is going to return an int then why not put that in its declaration


I could do int main() but I'm trying something other then a loop. Now I've got it to where it asks the user to continue and if he selects yes it calls the main() function again to restart, although that part isn't working lol. Still closses Mad

EDIT: This is what I now have:

Code:
// BasicCalculator.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "iostream"

int main()
{
   system("CLS");

   system("TITLE Basic Calculator 1.0");
   system("COLOR 2");

   short sht1 = 0;
   short sht2 = 0;
   char chrOP;
   char chrYN;

   std::cout << "Hello and welcome to the Basic Calculator Version 1.0!\n";
   std::cout << "Please type in your first number.\n";
   std::cin >> sht1;
   system("CLS");
   std::cout << "Please select one of the 4 operators below to use:\n";
   std::cout << " + (addition), - (subtraction), * (multiplication) or / (division)\n";
   std::cin >> chrOP;
   system("CLS");
   std::cout << "Please type in your second number.\n";
   std::cin >> sht2;
   system("CLS");
   
      switch (chrOP)
      {
         case '+':
            std::cout << (short)(sht1 + sht2) << "\n";
            break;
         case '-':
            std::cout << (short)(sht1 - sht2) << "\n";
            break;
         case '*':
            std::cout << (short)(sht1 * sht2) << "\n";
            break;
         case '/':
            std::cout << (short)(sht1 / sht2) << "\n";
            break;
         default:
            main();
            break;
      }
      std::cout << "Would you like to continue to calculate? (Y/N)\n";
      std::cin >> chrYN;

      switch(chrYN)
      {
      case 'Y' || 'y':
         main();
         break;
      default:
         return 1;
         break;
      }
   }
Back to top
View user's profile Send private message
hcavolsdsadgadsg
I'm a spammer
Reputation: 26

Joined: 11 Jun 2007
Posts: 5801

PostPosted: Sat Feb 27, 2010 12:53 am    Post subject: Reply with quote

don't call main again, loop instead.
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Sat Feb 27, 2010 4:02 am    Post subject: Reply with quote

slovach wrote:
don't call main again, loop instead.

Thanks for the tips guys! Really appreciate it Smile

I'm finally finished and here's my code:
Code:
// BasicCalculator.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include "iostream"

int main()
{
   system("TITLE C++ Basic Calculator By CometJack");
   system("COLOR 2");
   
   for (char chrAns = 'N'; chrAns == 'N';)
   {
   system("CLS");

   short sht1 = 0;
   short sht2 = 0;
   char chrOperator;

   std::cout << "Please type in your first number." << std::endl;
   std::cin >> sht1;
   system("CLS");
   std::cout << "Please select one of the 4 operators below to use:" << std::endl;
   std::cout << " + (addition), - (subtraction), * (multiplication) or / (division)" << std::endl;
   std::cin >> chrOperator;
   system("CLS");
   std::cout << "Please type in your second number." << std::endl;
   std::cin >> sht2;
   system("CLS");
   
      switch (chrOperator)
      {
         case '+':
            std::cout << sht1 << '+' << sht2 << '=' << sht1 + sht2 << std::endl;
            break;
         case '-':
            std::cout << sht1 << '-' << sht2 << '=' << sht1 - sht2 << std::endl;
            break;
         case '*':
            std::cout << sht1 << '*' << sht2 << '=' << sht1 * sht2 << std::endl;
            break;
         case '/':
            if (sht2 == 0)
            {
               std::cout << sht1 << '/' << sht2 << '=' << '0' << std::endl;
            }
            else
            {
               std::cout << sht1 << '/' << sht2 << '=' << sht1 / sht2 << std::endl;
            }
            break;
         default:
            std::cout << "Please use a correct operator: +, -, *, or /" << std::endl;
            break;
      }
      std::cout << "Would you like to exit the calculator? (Y/N)" << std::endl;
      std::cin >> chrAns;
   }
      return 0;
   }


If you want to, you can move this to the binaries section. It's an extremely simple application but someone might be able to add on to it Smile
Back to top
View user's profile Send private message
pkedpker
Master Cheater
Reputation: 1

Joined: 11 Oct 2006
Posts: 412

PostPosted: Mon Mar 01, 2010 2:15 am    Post subject: Reply with quote

#include "iostream"

probably wont work iostream is definitely a System include. How I know this? because if you were coding you would use the .h file but the iostream doesn't have it..

probably means its not in your folder but instead in
C:\program files\vc++\include
something like that

to access that folder you must use <>'s so it will look like this

#include <iostream>

otherwise you will have to copy/paste iostream from include folder in program files to your project folder which is what you shouldn't do because you will not edit iostream anyways right?

_________________
Hacks I made for kongregate.
Kongregate Universal Badge Hack: http://forum.cheatengine.org/viewtopic.php?p=4129411
Kongreate Auto Rating/Voter hack: http://forum.cheatengine.org/viewtopic.php?t=263576
Took a test lol
Back to top
View user's profile Send private message
TROLOLOLOLOLOLOLOLOLOLOLO
Expert Cheater
Reputation: -1

Joined: 27 Dec 2009
Posts: 100

PostPosted: Mon Mar 01, 2010 8:04 pm    Post subject: Reply with quote

Ah yes, I fixed that a while back when I was doing this project Smile Thanks though. I've updated my Basic Calculator a bit Laughing

Code:
// BasicCalculator.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>


int _tmain(int argc, _TCHAR* argv[])
{
   system("COLOR 02");
   system("TITLE Basic Calculator");
   short shtNum1, shtNum2;
   char chrOper, chrAns;
   do
   {
      system("CLS");
      std::cout << "Please type in your 1st numeric value." << std::endl;
      std::cin >> shtNum1;
      system("CLS");
      std::cout << "Please select on the following operators: +, -, * or /." << std::endl;
      std::cin >> chrOper;
      system("CLS");
      std::cout << "Please type in your 2nd numeric value." << std::endl;
      std::cin >> shtNum2;
      system("CLS");

      switch (chrOper)
      {
      case '+':
         std::cout << shtNum1 << '+' << shtNum2 << '=' << shtNum1 + shtNum2 << std::endl;
         break;
      case '-':
         std::cout << shtNum1 << '-' << shtNum2 << '=' << shtNum1 - shtNum2 << std::endl;
         break;
      case '*':
         std::cout << shtNum1 << '*' << shtNum2 << '=' << shtNum1 * shtNum2 << std::endl;
         break;
      case '/':
        if (shtNum2 != 0)
        {
           std::cout << shtNum1 << '/' << shtNum2 << '=' << shtNum1 / shtNum2 << std::endl;
        }
        else
        {
           std::cout << shtNum1 << '/' << shtNum2 << '=' << "undefined" << std::endl;
        }
         break;
      default:
         break;
      }
     
      std::cout << "Would you like to continue to use the calculator? (Y/N)" << std::endl;
      std::cin >> chrAns;
   } while (chrAns == 'Y' || chrAns == 'y');
   return 0;
}


I think that code above is much cleaner and efficient Smile
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