*

Author Topic: PistolKid's C++  (Read 118 times)

0 Members and 1 Guest are viewing this topic.

Offline PistolKid

  • S.T.A.L.K.E.R Admin
  • Vampire
  • *
PistolKid's C++
« on: 06-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)
Code: [Select]
#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;
}
« Last Edit: 06-10-2011 by PistolKid »

Major Danby replied indulgently with a superior smile: "But, Yossarian, suppose everyone felt that way."
Then," said Yossarian, "I'd certainly be a damned fool to feel any other way, wouldn't I?"

Online Paintcheck

  • **Donator**
  • GodLike
  • *
Re: PistolKid's C++
« Reply #1 on: 06-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.

Offline PistolKid

  • S.T.A.L.K.E.R Admin
  • Vampire
  • *
Re: PistolKid's C++
« Reply #2 on: 06-10-2011 »
Yup, that was the problem. Wow, can't believe I missed that.




Major Danby replied indulgently with a superior smile: "But, Yossarian, suppose everyone felt that way."
Then," said Yossarian, "I'd certainly be a damned fool to feel any other way, wouldn't I?"

Offline PistolKid

  • S.T.A.L.K.E.R Admin
  • Vampire
  • *
Re: PistolKid's C++
« Reply #3 on: 07-10-2011 »
3 days of learning C++ and I have this:


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

Major Danby replied indulgently with a superior smile: "But, Yossarian, suppose everyone felt that way."
Then," said Yossarian, "I'd certainly be a damned fool to feel any other way, wouldn't I?"

 

ShoutBox

Last 15 Shouts:

 

PistolKid

Yesterday at 10:58 PM
japanese linograph community portals
 

Romka

Yesterday at 10:39 PM
If you're making friendship bracelets, you're playing Online Texad Hold'em poker and you don't even have to read this if you're looking for an Oxford dictionary because you already have a guided tour to Stockholm with that Caregiver job and Herbal Essence cupons and kidney diabetes diet.
 

Steven :D

Yesterday at 08:06 PM
haha its gone
fuck you arthur
 

Steven :D

Yesterday at 08:06 PM
music go away
 

Steven :D

Yesterday at 08:05 PM
music go away
 

Steven :D

Yesterday at 08:05 PM
music go away
 

Steven :D

Yesterday at 08:05 PM
music go away
 

Steven :D

Yesterday at 08:05 PM
music go away
 

Steven :D

Yesterday at 08:05 PM
music go away
 

Redbark

Yesterday at 08:05 PM
Shall we spam to get rid of the music?
 

lolKieck

Yesterday at 07:59 PM
god dammit king
 

Gonztah

Yesterday at 07:32 PM
It's annoying when trying to browse the forums and listen to music at the same time.
 

Ket

Yesterday at 07:07 PM
This song fits with plunger's interpetration of Snazzy Gaming apology.

Show 50 latest

Servers

Members
Stats
  • Total Posts: 112146
  • Total Topics: 10176
  • Online Today: 186
  • Online Ever: 370
  • (30-12-2011)
Users Online