Jump to content

Primary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Secondary: Sky Slate Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate Marble
Pattern: Blank Waves Squares Notes Sharp Wood Rockface Leather Honey Vertical Triangles
Photo

A problem in the "cout" command of C++


  • Please log in to reply
4 replies to this topic

#1
God of LoL

God of LoL

    Sweet Potato

  • Members
  • 10,556 posts
  • LocationIn the Bato.cave.
I want to teach my cousin about classes. I'm right now trying to make an example program, which, for some reason, won't just start. Here's the program's code, now if you could please tell me where I'm wrong, I would be grateful.

Spoiler


Thank you for your time.

Don't mind the //. These are comments.

kfi6l.jpg


#2
pizhhh

pizhhh

    Baked Potato

  • Members
  • 1,029 posts
  • Locationin jail
What seems to be the problem?

I removed #include "StdAfx.h"
and added cin.ignore(); and cin.get(); before return 0; and got it to compile and run just fine.
Are those important? (sorry, I'm still just a beginner in C++ myself.)

#3
Laurens D

Laurens D

    Baked Potato

  • tC Donator
  • 1,475 posts
  • Locationin the tower!
Try this one:

#include "stdafx.h"
#include "iostream"
using namespace std;

class human
{ //Κλάση. Το βασιΚόΤερο παράδειγμα ΚληρονομιΚόΤηΤας. Μία Κλάση έχει Κάποια χαραΚΤηρισΤιΚά. ο άνθρωπος π.χ. έχει...
	public:
	int Intelligence; //ευφυΐα...
	int Strength; //δύναμη...
	int Agility; //Και ΤαχύΤηΤα.
	int Score;

	int range(); //αυΤοδυναμία...
};

int human::range()
{
	return Agility * Strength;
}

int main(array<System::String ^> ^args)
{

	human Warrior; //αυΤό, ΚυριάΚο, είναι ένα ανΤιΚείμενο. Έχει Τις ιδιόΤηΤες μίας Κλάσης που θέσαμε.
	human Thief;
	human Wizard;

	int range1, range2, range3;

	//Τώρα θα δώσουμε Τιμές σΤα ανΤιΚείμενα.
	Warrior.Intelligence = 14;
	Warrior.Strength = 132;
	Warrior.Agility = 45;
	Warrior.Score = (Warrior.Strength / Warrior.Agility / Warrior.Intelligence);

	Thief.Intelligence = 43;
	Thief.Strength= 10;
	Thief.Agility= 102;
	Thief.Score= (Thief.Agility / Thief.Intelligence / Thief.Strength);

	Wizard.Intelligence = 121;
	Wizard.Strength = 4;
	Wizard.Agility = 30;
	Wizard.Score = (Wizard.Intelligence / Wizard.Agility / Wizard.Strength);

	range1 = Warrior.range();
	range2 = Thief.range();
	range3 = Wizard.range();

	cout << "Warrior has" << Warrior.Intelligence << "Int, " << Warrior.Strength << "Str, " << Warrior.Agility << " Agt, with a total score of" << Warrior.Score << ". His Level is" << range1 << "\n" ;
	cout << "Thief has" << Thief.Intelligence << "Int, " << Thief.Strength << "Str, " << Thief.Agility << "Agt, with a total score of" << Thief.Score << "His Level is" << range2 << "\n" ;
	cout << "Wizard has" << Wizard.Intelligence << "Int, " << Wizard.Strength << "Str, " << Wizard.Agility << "Agt, with a total score of" << Wizard.Score << "His Level is" << range3 << "\n" ;

    system ("pause");

	return 0;
}


Edited by Laurens D, 12 August 2012 - 02:08 PM.

Posted Image

This is not my fault!

You could have bought my cookies.


#4
God of LoL

God of LoL

    Sweet Potato

  • Members
  • 10,556 posts
  • LocationIn the Bato.cave.
Thanks!! :D

kfi6l.jpg


#5
Angelo.

Angelo.

    Couch Potato

  • Members
  • 3,488 posts
  • Locationsleeping on a cloud
problem solved!