 |
Cheat Engine The Official Site of Cheat Engine
|
| View previous topic :: View next topic |
| Author |
Message |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 27, 2007 7:29 pm Post subject: C++ Questions |
|
|
Ok, well my first question is how come this code won't work. I'm using Dev-C++ compilier. This is a simple code that devides's fractions (made this cuz my friends sucks at dividing.
| Code: |
#include <iostream>
using namespace std;
int dev ( int fraction1, int fraction2 );
int main()
{
int fraction1;
int fraction2;
cout<<"Please input in one fraction:\n";
cin>> fraction1;
cin.ignore();
cout<<"Please input another fraction:\n";
cin>> fraction2;
cin.ignore();
cout<<"The quotient is"( <<dev ( fraction1, fraction2 ) <<"\n";
cin.get();
}
int dev ( int fraction1, int fraction2 )
{
return fraction1 / fraction2;
}
|
If this helps you it says "expected primary-expression before '<<' token". Pointing at line 19.
Ok, second quesiton. the command using name std allows you to use commands from the standard library (std), but what are those commands, and what other using name blablabla are there and what are there commands.
P.S
What does void main() mean? The tutorial I'm taking doesn't say.
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
appalsap Moderator
Reputation: 0
Joined: 27 Apr 2006 Posts: 6753 Location: Pakistan
|
Posted: Sun May 27, 2007 7:46 pm Post subject: |
|
|
void means it does not return a value. do not use namespaces if you do not know what they are, prefix std functions with std:: to let the compiler know you are using a function of the std class. Here is your code, fixed.
| Code: |
#include <iostream>
int dev ( int fraction1, int fraction2 );
int main()
{
int fraction1, fraction2;
std::cout<<"One fraction please: ";
std::cin >> fraction1;
std::cout << "Another fraction please: ";
std::cin >> fraction2;
std::cout << "The quotient is " << dev(fraction1, fraction2) << std::endl;
std::cin.ignore(); std::cin.get();
return 0;
}
int dev ( int fraction1, int fraction2 )
{
return fraction1 / fraction2;
}
|
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 27, 2007 7:53 pm Post subject: |
|
|
| appalsap wrote: | void means it does not return a value. do not use namespaces if you do not know what they are, prefix std functions with std:: to let the compiler know you are using a function of the std class. Here is your code, fixed.
| Code: |
#include <iostream>
int dev ( int fraction1, int fraction2 );
int main()
{
int fraction1, fraction2;
std::cout<<"One fraction please: ";
std::cin >> fraction1;
std::cout << "Another fraction please: ";
std::cin >> fraction2;
std::cout << "The quotient is " << dev(fraction1, fraction2) << std::endl;
std::cin.ignore(); std::cin.get();
return 0;
}
int dev ( int fraction1, int fraction2 )
{
return fraction1 / fraction2;
}
|
|
Thanks appal, but one problem, IT DON'T DEVIDE FRACTIONS! It only divides whole numbers. If I put like 1/3, 5/7 as my first or second number it closes. And what doesn end endl do and why did you put return 0. And my question wasn't what namespaces were, it was simply what other namespaces were there besides std and what are their commands and what they do? You don't have a msn do you so I can talk to you?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sun May 27, 2007 7:54 pm Post subject: |
|
|
| oib111 wrote: | | appalsap wrote: | void means it does not return a value. do not use namespaces if you do not know what they are, prefix std functions with std:: to let the compiler know you are using a function of the std class. Here is your code, fixed.
| Code: | #include <iostream>
int main(int argc, const char* argv[])
{
float dividend, divisor;
std::cout<<"The dividend please: ";
std::cin >> dividend;
std::cout << "The divisor please: ";
std::cin >> divisor;
std::cout << "The quotient is " << (dividend/divisor) << std::endl;
std::cin.ignore(); std::cin.get();
return 0;
}
|
|
Thanks appal, but one problem, IT DON'T DEVIDE FRACTIONS! It only divides whole numbers. If I put like 1/3, 5/7 as my first or second number it closes. And what doesn end endl do and why did you put return 0. And my question wasn't what namespaces were, it was simply what other namespaces were there besides std and what are their commands and what they do? You don't have a msn do you so I can talk to you? |
Make the type float and not int, and stick the number in as a decimal and not a fraction.
Endl ends the line.
MSDN is your friend.
Fixed code in the quote.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 27, 2007 8:42 pm Post subject: |
|
|
| Flyte wrote: | | oib111 wrote: | | appalsap wrote: | void means it does not return a value. do not use namespaces if you do not know what they are, prefix std functions with std:: to let the compiler know you are using a function of the std class. Here is your code, fixed.
| Code: | #include <iostream>
int main(int argc, const char* argv[]) //what does that do, I always knew it to be int main()
{
float dividend, divisor;
std::cout<<"The dividend please: ";
std::cin >> dividend;
std::cout << "The divisor please: ";
std::cin >> divisor;
std::cout << "The quotient is " << (dividend/divisor) << std::endl;
std::cin.ignore(); std::cin.get();
return 0; //why did you put return 0, what does it do?
}
|
|
Thanks appal, but one problem, IT DON'T DEVIDE FRACTIONS! It only divides whole numbers. If I put like 1/3, 5/7 as my first or second number it closes. And what doesn end endl do and why did you put return 0. And my question wasn't what namespaces were, it was simply what other namespaces were there besides std and what are their commands and what they do? You don't have a msn do you so I can talk to you? |
Make the type float and not int, and stick the number in as a decimal and not a fraction.
Endl ends the line.
MSDN is your friend.
Fixed code in the quote. |
Thx dude. But can you put answers in the code where I Put questions?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sun May 27, 2007 8:50 pm Post subject: |
|
|
The second declaration of main allows it to be ran from the command line with arguments.
argc = number of arguments
argv = arguments
The return is there for exit code purposes, traditionally it is 0, but it can be anything really.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 27, 2007 8:55 pm Post subject: |
|
|
| Flyte wrote: | | The return is there for exit code purposes, traditionally it is 0, but it can be anything really. |
You mean it closes the program? Or does it matter if I have it in my code or not?
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Sun May 27, 2007 8:59 pm Post subject: |
|
|
| oib111 wrote: | | Flyte wrote: | | The return is there for exit code purposes, traditionally it is 0, but it can be anything really. |
You mean it closes the program? Or does it matter if I have it in my code or not? |
The return code is for debugging or when you run it in the context of another process. Keep it in there, it is a good habit.
|
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun May 27, 2007 9:30 pm Post subject: |
|
|
mkay
_________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
|
|
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
|
|