HyperGaming Network

General Discussion => Entertainment Forums => Computing => Topic started by: deluxulous on 05-10-2011

Title: PistolKid's C++
Post by: deluxulous on 05-10-2011
so yeah. i'm beginning to learn C++. It's pretty fun so far, and it's gone very well. I suppose I'll use this thread to document my progress and post issues. I just ran into a problem.
(I'm learning forward declaratory statements by the way)

#include <iostream>

int DoMath(int, int, int, int) \\ Forward declaratory statement. Sets up a function before the program sees it in the main() function, and also before you actually define it

int main()
{
   using namespace std;
cout << "3 + 4 * 5 / 6 = " << DoMath(3 + 4 * 5 / 6) << endl; // Compiler reports "error C2660: 'DoMath' : function does not take 1 arguments"
   return 0;
}

int DoMath(int a, int b, int c, int d)
{
   return a + b * c / d;
}
Title: Re: PistolKid's C++
Post by: Paintcheck on 05-10-2011
You need to declare your variables. When you call DoMath(3 + 4 * 5 / 6), the computer evaluates that as DoMath(6.333333333333) which is just 1 double in the argument. The computer is expecting 4 integers. 

You need to declare a = 3, b= 4, c = 5, d = 6. Then call it as DoMath(a, b, c, d) OR leave it as it is and call DoMath(3, 4, 5, 6). Either of those should fix your problem.
Title: Re: PistolKid's C++
Post by: deluxulous on 06-10-2011
Yup, that was the problem. Wow, can't believe I missed that.



Title: Re: PistolKid's C++
Post by: deluxulous on 06-10-2011
3 days of learning C++ and I have this:
(https://forums.hypergamer.net/proxy.php?request=http%3A%2F%2Fimg267.imageshack.us%2Fimg267%2F2429%2Fsimplecalculator.png&hash=4966df62efd3927b2af671446918b3d8e5ba4aae)

did this for a quiz. the questions are:
1) Write a program that reads two numbers from the user, adds them together, and then outputs the answer. The program should use two functions: A function named ReadNumber() should be used to get an integer from the user, and a function named "WriteAnswer" should be used to output the answer. You do not need to write a function to do the adding.

2) Modify the program you wrote in #1 so that the function to read a number from the user and the function to output the answer are in a separate file called "io.cpp". Use a forward declaration to access them from your main() function, which should live in "main.cpp".

3) Modify the program you wrote in #2 so that it uses a header file to access the functions instead of forward declarations. Make sure your header file uses header guards.


yayyyy