| View previous topic :: View next topic |
| Author |
Message |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Fri Feb 26, 2010 11:59 pm Post subject: [C++] #include <iostream> error - FIXED! |
|
|
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 |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Feb 27, 2010 12:06 am Post subject: |
|
|
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 |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Feb 27, 2010 12:11 am Post subject: |
|
|
| 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
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sat Feb 27, 2010 12:23 am Post subject: |
|
|
| 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 |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Feb 27, 2010 12:36 am Post subject: |
|
|
| 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
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 |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Feb 27, 2010 12:53 am Post subject: |
|
|
| don't call main again, loop instead.
|
|
| Back to top |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Sat Feb 27, 2010 4:02 am Post subject: |
|
|
| slovach wrote: | | don't call main again, loop instead. |
Thanks for the tips guys! Really appreciate it
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
|
|
| Back to top |
|
 |
pkedpker Master Cheater
Reputation: 1
Joined: 11 Oct 2006 Posts: 412
|
Posted: Mon Mar 01, 2010 2:15 am Post subject: |
|
|
#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?
_________________
|
|
| Back to top |
|
 |
TROLOLOLOLOLOLOLOLOLOLOLO Expert Cheater
Reputation: -1
Joined: 27 Dec 2009 Posts: 100
|
Posted: Mon Mar 01, 2010 8:04 pm Post subject: |
|
|
Ah yes, I fixed that a while back when I was doing this project Thanks though. I've updated my Basic Calculator a bit
| 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
|
|
| Back to top |
|
 |
|