💡 [Proof]I am learning C++

Posts 16–30 of 47 · Page 2 of 4
Also, if you don't want it to go over 100%

Code:
	if(pages > total)
	{
             cout << "Blah blah";
     } else {
Quote Originally Posted by flashlight95 View Post
Also, if you don't want it to go over 100%

Code:
	if(pages > total)
	{
             cout << "Blah blah";
     } else {
I just learned about the if and else if and while if else if and all them loops. lolz.
I could do that, which I will end up making the code more complex, just as a way to test my skills I am learning, but as of the pause, I haven't learned that yet. How would I do that?
system("PAUSE"); works

but

cin.get(); is probably better
Class:
Code:
#include <iostream>
#include <ctime>

class Player1
{
public:
	int Health;
	Player1();

	int Attack();
	int Attack1();
	int Attack2();
	int Burn(int damage);
	int Heal();

	void Damage(int damage);
	void DisplayHP();

};

class Monster1
{
public:
	int Health;
	Monster1();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};

class Monster2
{
public:
	int Health;
	Monster2();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};

class Monster3
{
public:
	int Health;
	Monster3();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};
Main:
Code:
int main()
{
	srand( (unsigned) time(0) );
    Instructions();
    return 0;
}

void Instructions()
{
    string exit;

    cout << "Do you want to start?: ";
    cin >> exit;
    if (exit == "no")
    {
    }
    else if (exit == "yes")
    {
        system ("cls");

        cout << "Attack the monster!" << endl 
			 << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

        system("pause");
       
        pick();

        system("pause");
        system ("cls");
    }

	else if (exit == "mudkipz")
	{
		EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
		DrawMenuBar(GetConsoleWindow());

		intro();
	}
}

void pick()
{
    string pick;

    cout << "Which monster do you want to fight? (Truck, Tank, Plane): ";
    cin >> pick;

    if (pick == "Truck")
    {
        system("cls");
        Combat1();
    }
    else if (pick == "Tank")
    {
        system("cls");
        Combat2();
    }
	else if (pick == "Plane")
	{
		system ("cls");
		Combat3();
	}

}


Player1::Player1()
{
    Health = 100;
}

Monster1::Monster1()
{
    Health = 500;
}


Monster2::Monster2()
{
    Health = 1000;
}

Monster3::Monster3()
{
    Health = 200;
}

void Player1::DisplayHP()
{
    cout << "Your HP: " << Health << endl;
}

void Monster1::DisplayHP()
{
    cout << "Truck's HP: " << Health << endl;
}


void Monster2::DisplayHP()
{
    cout << "Tank's HP: " << Health << endl;
}

void Monster3::DisplayHP()
{
    cout << "Plane's HP: " << Health << endl;
}

void Player1::Damage(int damage)
{
    Health -= damage;
}

void Monster1::Damage(int damage)
{
    Health -= damage;
}


void Monster2::Damage(int damage)
{
    Health -= damage;
}

void Monster3::Damage(int damage)
{
    Health -= damage;
}

int Player1::Heal()
{
    int randdamage;
    randdamage = -(rand() % 20 + 1);

    cout << "You healed: " << -(randdamage) << endl;
    return randdamage;
}

int Player1::Attack()
{
    int randdamage;
    randdamage = rand() % 4 + 20;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}

int Player1::Attack1()
{
    int randdamage;
    randdamage = rand() % 100 + 5;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}

int Player1::Attack2()
{
    int randdamage;
    randdamage = rand() % 4 + 10;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}


int Monster1::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 10 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 20 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}


int Monster2::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 5 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 8 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}

int Monster3::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 5 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 50 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}

void Combat1()
{
    int choice;

    Player1 User;
    Monster1 Monster;

    User.DisplayHP();
    Monster.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;
		cin >> choice;
        switch (choice)
        {               
        case 1:
            Monster.Damage(User.Attack());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Monster.Damage(User.Attack1());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
			break;

		case 1337:
			Monster.Damage(1000000);
			Monster.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;

        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
		
			system("pause");
            system("cls");
            Instructions();
            break;
        }

        if (Monster.Health <= 0)
        {
			MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            cout << "You ween" << endl;
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}

void Combat2()
{
    int choice;

    Player1 User;
    Monster2 Tank;

    User.DisplayHP();
    Tank.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

		cin >> choice;
        switch (choice)
        {               
        case 1:
            Tank.Damage(User.Attack());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Tank.Damage(User.Attack1());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
			break;

		case 4:
			Tank.Damage(User.Attack2());
			Tank.DisplayHP();
			User.Damage(Tank.RandomAttack());
			User.DisplayHP();
			break;

		case 1337:
			Tank.Damage(1000000);
			Tank.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;
        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
        if (Tank.Health <= 0)
        {
            MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}

void Combat3()
{
    int choice;

    Player1 User;
    Monster3 Plane;

    User.DisplayHP();
    Plane.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

		cin >> choice;
        switch (choice)
        {               
        case 1:
            Plane.Damage(User.Attack());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Plane.Damage(User.Attack1());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
			break;

		case 4:
			Plane.Damage(User.Attack2());
			Plane.DisplayHP();
			User.Damage(Plane.RandomAttack());
			User.DisplayHP();
			break;

		case 1337:
			Plane.Damage(1000000);
			Plane.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;
        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }

        if (Plane.Health <= 0)
        {
            MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}
hehe. probably should have put the combats into classes, but i did this a long time ago. missing some stuff cuz it would be way too long.

EDIT: @the noob on top of me. why the hell would the program close randomly because of int main()? ya sure u aint sleepin in class?
Quote Originally Posted by scimmyboy View Post
Class:
Code:
#include <iostream>
#include <ctime>

class Player1
{
public:
	int Health;
	Player1();

	int Attack();
	int Attack1();
	int Attack2();
	int Burn(int damage);
	int Heal();

	void Damage(int damage);
	void DisplayHP();

};

class Monster1
{
public:
	int Health;
	Monster1();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};

class Monster2
{
public:
	int Health;
	Monster2();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};

class Monster3
{
public:
	int Health;
	Monster3();

	int RandomAttack();
	void Damage(int damage);
	void DisplayHP();

};
Main:
Code:
int main()
{
	srand( (unsigned) time(0) );
    Instructions();
    return 0;
}

void Instructions()
{
    string exit;

    cout << "Do you want to start?: ";
    cin >> exit;
    if (exit == "no")
    {
    }
    else if (exit == "yes")
    {
        system ("cls");

        cout << "Attack the monster!" << endl 
			 << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

        system("pause");
       
        pick();

        system("pause");
        system ("cls");
    }

	else if (exit == "mudkipz")
	{
		EnableMenuItem(GetSystemMenu(GetConsoleWindow(), FALSE), SC_CLOSE , MF_GRAYED);
		DrawMenuBar(GetConsoleWindow());

		intro();
	}
}

void pick()
{
    string pick;

    cout << "Which monster do you want to fight? (Truck, Tank, Plane): ";
    cin >> pick;

    if (pick == "Truck")
    {
        system("cls");
        Combat1();
    }
    else if (pick == "Tank")
    {
        system("cls");
        Combat2();
    }
	else if (pick == "Plane")
	{
		system ("cls");
		Combat3();
	}

}


Player1::Player1()
{
    Health = 100;
}

Monster1::Monster1()
{
    Health = 500;
}


Monster2::Monster2()
{
    Health = 1000;
}

Monster3::Monster3()
{
    Health = 200;
}

void Player1::DisplayHP()
{
    cout << "Your HP: " << Health << endl;
}

void Monster1::DisplayHP()
{
    cout << "Truck's HP: " << Health << endl;
}


void Monster2::DisplayHP()
{
    cout << "Tank's HP: " << Health << endl;
}

void Monster3::DisplayHP()
{
    cout << "Plane's HP: " << Health << endl;
}

void Player1::Damage(int damage)
{
    Health -= damage;
}

void Monster1::Damage(int damage)
{
    Health -= damage;
}


void Monster2::Damage(int damage)
{
    Health -= damage;
}

void Monster3::Damage(int damage)
{
    Health -= damage;
}

int Player1::Heal()
{
    int randdamage;
    randdamage = -(rand() % 20 + 1);

    cout << "You healed: " << -(randdamage) << endl;
    return randdamage;
}

int Player1::Attack()
{
    int randdamage;
    randdamage = rand() % 4 + 20;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}

int Player1::Attack1()
{
    int randdamage;
    randdamage = rand() % 100 + 5;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}

int Player1::Attack2()
{
    int randdamage;
    randdamage = rand() % 4 + 10;

    cout << "You dealt: " << randdamage << " damage" << endl;
    return randdamage;
}


int Monster1::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 10 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 20 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}


int Monster2::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 5 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 8 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}

int Monster3::RandomAttack()
{
    int randdamage;
    int randattack;

    randattack = rand() % 2 + 1;

    if (randattack == 1)
    {
        randdamage = rand() % 5 + 5;
    }
    else if (randattack == 2)
    {
        randdamage = rand() % 50 + 5;
    }
   
    cout << "You received: " << randdamage << " damage" << endl;
    return randdamage;
}

void Combat1()
{
    int choice;

    Player1 User;
    Monster1 Monster;

    User.DisplayHP();
    Monster.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;
		cin >> choice;
        switch (choice)
        {               
        case 1:
            Monster.Damage(User.Attack());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Monster.Damage(User.Attack1());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Monster.DisplayHP();
            User.Damage(Monster.RandomAttack());
            User.DisplayHP();
			break;

		case 1337:
			Monster.Damage(1000000);
			Monster.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;

        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
		
			system("pause");
            system("cls");
            Instructions();
            break;
        }

        if (Monster.Health <= 0)
        {
			MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            cout << "You ween" << endl;
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}

void Combat2()
{
    int choice;

    Player1 User;
    Monster2 Tank;

    User.DisplayHP();
    Tank.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

		cin >> choice;
        switch (choice)
        {               
        case 1:
            Tank.Damage(User.Attack());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Tank.Damage(User.Attack1());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Tank.DisplayHP();
            User.Damage(Tank.RandomAttack());
            User.DisplayHP();
			break;

		case 4:
			Tank.Damage(User.Attack2());
			Tank.DisplayHP();
			User.Damage(Tank.RandomAttack());
			User.DisplayHP();
			break;

		case 1337:
			Tank.Damage(1000000);
			Tank.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;
        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
        if (Tank.Health <= 0)
        {
            MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}

void Combat3()
{
    int choice;

    Player1 User;
    Monster3 Plane;

    User.DisplayHP();
    Plane.DisplayHP();

    while (User.Health > 0)
    {
        cout << "Press 1 to use assault rifle (weak/accurate)" << endl
			 << "Press 2 to big boom (stronger/less accurate)" << endl 
			 << "Press 3 to heal (You can't attack)" << endl;

		cin >> choice;
        switch (choice)
        {               
        case 1:
            Plane.Damage(User.Attack());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
            break;

        case 2:
            Plane.Damage(User.Attack1());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
            break;

        case 3:
            User.Damage(User.Heal());
            Plane.DisplayHP();
            User.Damage(Plane.RandomAttack());
            User.DisplayHP();
			break;

		case 4:
			Plane.Damage(User.Attack2());
			Plane.DisplayHP();
			User.Damage(Plane.RandomAttack());
			User.DisplayHP();
			break;

		case 1337:
			Plane.Damage(1000000);
			Plane.DisplayHP();
			User.DisplayHP();
			cout << "you cheater" << endl;
			break;
        }

        if (User.Health <= 0)
        {
            MessageBox(NULL, TEXT("Game Over GG"), TEXT("Game Over GG"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }

        if (Plane.Health <= 0)
        {
            MessageBox(NULL, TEXT("You ween"), TEXT("You ween"), MB_OK);
            system("pause");
            system("cls");
            Instructions();
            break;
        }
    }
}


hehe. probably should have put the combats into classes, but i did this a long time ago. missing some stuff cuz it would be way too long.

EDIT: @the noob on top of me. why the hell would the program close randomly because of int main()? ya sure u aint sleepin in class?
Thats from thatr Guy in youtube. Or its from C++ for Dummies
Quote Originally Posted by Stephen View Post


Thats from thatr Guy in youtube. Or its from C++ for Dummies
uhm no its not. those vids and C++ for dummies is bullshit
Quote Originally Posted by mmbob View Post
Definitely not, you NEVER use void main();
really cus im taking a Comp sci class and im in the 3rd level of it and if we use int main we get kicked out of class for good.
we must use void main
our teacher is also the same guy who helps IBM Dell and microsoft
but i guess you kno more then him so ok....you win...dont use void main use int main and let your program end for no reason and then wonder y its doing so
if you include conio.h then you can use getch();
to pause it for one char input with out stopping the program for the time
Quote Originally Posted by DBag4Life69 View Post


There's a big problem there with how you re-wrote that. :-|
p hasn't been defined, and pages is also not defined. I know HOW to do that, but no matter what, your code there WILL not work, unless you change a couple of things. ;-)
yea i noticed i messed up there a bit so im trying to do it now by doing it in my compiler, at first i just wrote it out in the reply box then as i posted i noticed the errors so im rewriting it now i will post back in a minute
and p was defined in the int calcu as an input (u need to use different names as u pass values thru functions so in main it is pages in the function it is p
Quote Originally Posted by DBag4Life69 View Post


Lolz. I know what you mean.
Most people aren't very determined.

I am.

I am determined to learn C++ as a language, so I can make stuff that I can use for ANYTHING.
Not just for hacks.

Now, I know that's what my inspiration WAS to start this determination, but my inspiration changed now.

But ANYWAYS, I figured I would release that code, since it's proof that I AM in fact learning SOMETHING, cuz I wrote that all on my own.
nice i believe in you bro im learning it also so we can help each other i have actually made on hack but im trying to get it so it can not dc
[php]
// Credits:
// D-Vid aka Illusionz
// flashlight95 -- For the idea of usin the if
#include <iostream>

int main()
{
using namespace std;
float CppPrimer;
float total;
int pages;

cout << "Enter the total amount of pages that you've read so far: \n\n";
cin >> pages;
cout << endl;
CppPrimer = 1225;
total = 2501;
if (pages>total)
{
cout << "You input the incorrect value, it has to be less than 2501 pages." << endl;
system("PAUSE");
cout << endl;
}
else if (pages<total)
{
cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << pages / CppPrimer * 100 << "%" << endl;
cout << "Percentage TOTAL outta all the books: " << pages / total * 100 << "%" << endl;
system("PAUSE");
cout << endl;
}
else
{
cout << "You're DONE learning from those books!" << endl;
system("PAUSE");
cout << endl;
}

}
[/php]

I just added something in there.
What'ya think so far?
Quote Originally Posted by DBag4Life69 View Post
[php]
// Credits: D-Vid aka Illusionz
#include <iostream>

int main()
{
using namespace std;
float CppPrimer;
float total;
int pages;

cout << "Enter the total amount of pages that you've read so far: \n\n";
cin >> pages;
cout << endl;
CppPrimer = 1225;
total = 2501;
if (pages>total)
{
cout << "You input the incorrect value, it has to be less than 2501 pages." << endl;
system("PAUSE");
cout << endl;
}
else if (pages<total)
{
cout << "Percentage outta the C++ Primer Plus: 5th Edition: " << pages / CppPrimer * 100 << "%" << endl;
cout << "Percentage TOTAL outta all the books: " << pages / total * 100 << "%" << endl;
system("PAUSE");
cout << endl;
}
else
{
cout << "You're DONE learning from those books!" << endl;
system("PAUSE");
cout << endl;
}

}
[/php]I just added something in there.
What'ya think so far?
what compiler are you usen.
the one im usen wont let me use system("PAUSE");
ever but im usen turbo c++ 3.0 IDE

also i did this but the funtion still returns nothing

all tho its the same structure as i use in all my programs
but im tired its Saturday and i dont want to think to much so i give up on trying it but thats the way i was taught to code by my teacher at school

Code:
#include <iostream.h>
#include <conio.h>

int calcucpp(int p,int CPP){
    int temp;
    temp = p/CPP;
    temp = temp * 100;
    return temp;
}

void main(){
    clrscr();
    double CppPrimer = 1225;
    double total = 2501;
    int pages;

    double temp;

    cout<<"Enter the total amount of pages read so far : \n\n";
    cin>>pages;

    cout <<"% of CppPrimer "<<calcucpp(pages,CppPrimer)<<endl;

    cout <<"% of total pages "<<pages/total * 100<<endl;
    getch();
}#include <iostream.h>
#include <conio.h>
#include <math.h>
const int CppPrimer = 1225;
const int total = 2501;

int calcuCPPP(int p){
    int temp;
    temp=(p/CppPrimer)*100;
    return(temp);
}
int calcutotal(int p){
    int temp;
    temp = (p/total)*100;
    return(temp);
}

void main(){
    int pages;

    cout<<"Enter the total amount of pages that you've read so far:\n";
    cin>>pages;
    cout<<endl;

    cout<<"Percentage outta the C++ Primer Plus: 5th Edition: "<<calcuCPPP(pages)<<"%"<<endl;
    cout<<"Percentage outta all the books: "<<calcutotal(pages)<<"%"<<endl;
    getch();
}
Quote Originally Posted by tahha View Post
what compiler are you usen.
the one im usen wont let me use system("PAUSE");
ever but im usen turbo c++ 3.0 IDE

also i did this but the funtion still returns nothing

all tho its the same structure as i use in all my programs
but im tired its Saturday and i dont want to think to much so i give up on trying it but thats the way i was taught to code by my teacher at school

Code:
#include <iostream.h>
#include <conio.h>

int calcucpp(int p,int CPP){
    int temp;
    temp = p/CPP;
    temp = temp * 100;
    return temp;
}

void main(){
    clrscr();
    double CppPrimer = 1225;
    double total = 2501;
    int pages;

    double temp;

    cout<<"Enter the total amount of pages read so far : \n\n";
    cin>>pages;

    cout <<"% of CppPrimer "<<calcucpp(pages,CppPrimer)<<endl;

    cout <<"% of total pages "<<pages/total * 100<<endl;
    getch();
}#include <iostream.h>
#include <conio.h>
#include <math.h>
const int CppPrimer = 1225;
const int total = 2501;

int calcuCPPP(int p){
    int temp;
    temp=(p/CppPrimer)*100;
    return(temp);
}
int calcutotal(int p){
    int temp;
    temp = (p/total)*100;
    return(temp);
}

void main(){
    int pages;

    cout<<"Enter the total amount of pages that you've read so far:\n";
    cin>>pages;
    cout<<endl;

    cout<<"Percentage outta the C++ Primer Plus: 5th Edition: "<<calcuCPPP(pages)<<"%"<<endl;
    cout<<"Percentage outta all the books: "<<calcutotal(pages)<<"%"<<endl;
    getch();
}
Quote Originally Posted by scimmyboy View Post
Class:
EDIT: @the noob on top of me. why the hell would the program close randomly because of int main()? ya sure u aint sleepin in class?
hey dick can it

the return 0; he was missing would crash if he had a longer program ive done it before and ended up losing the work.

if you have

Code:
int main(){
//lots of code here
}
then it can crash

but
Code:
int main(){
cout<<"Hey";
}
theres no need for it cus the program ends before theres a chance for it to lose the track of main

as for
Code:
void main(){
//code here
}
its not trying to return or look for the return of the value of main
so it wouldnt have an issue at all
if you would get your head out of the books telling you the wrong information and learn the RIGHT way you would see this.

Quote Originally Posted by DBag4Life69 View Post


OH your usen the vc well no wonder your able to use int main and system("PAUSE");

that version of c++ is dulled down for the easy of use

if you use an older compiler it will make it alot harder to get errors fixed and make you really learn the syntax of c++ so you dont make errors as much

vc++ pretty much tells you exactly where the error is

my compiler will tell you the line and the error not that your missing a ";" at line 12 col 33
but "unexpected end of line at line 12"
No need for that total variable just wasting memory. Change it to pages < 2501
Posts 16–30 of 47 · Page 2 of 4

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us