• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

zonets first program :)

Zonet

Web Developer
Joined
Sep 1, 2008
Messages
4,393
Reaction score
52
Location
Tibia VS RL-life, guess whos back?
Here is my first program, just readed 5 minutes ;(

Code:
#include <iostream>
using namespace std;

int main()
{
int length, width;
length = 10;
width = 8;
	cout << "The length is " << length "\n ";
	cout << "The width is " << width "\n ";
	cout << "The area is " << length * width;
return 0;
}

Is right :)?
 
Keep learning.

Read this:
cin - C++ Reference

And make something like:
Code:
Please type width:
User: 5
Please type height:
User: 10
The area is: 5*10 = 50
 
Thanks Sality, I've read book .pdf.
I'm also going to buy a book as Kiper recommended :)

Edit: Would be something like this or, tell me if any errors :p

Code:
#include <iostream>
using namespace std;

int main()
{
int length, width;
	cout << "Type a length: \n";
	cin >> length;
	cout << "Okay, the length is: " << length;


	cout << "Type a width: \n";
	cin >> width;
	cout << "Okay, the width is:" << width;

	cout << "So, the area will be:" << length * width;
return 0;
}
 
Last edited:
Thanks Sality, I've read book .pdf.
I'm also going to buy a book as Kiper recommended :)

Edit: Would be something like this or, tell me if any errors :p

Code:
#include <iostream>
using namespace std;

int main()
{
int length, width;
	cout << "Type a length: \n";
	cin >> length;
	cout << "Okay, the length is: " << length;


	cout << "Type a width: \n";
	cin >> width;
	cout << "Okay, the width is:" << width;

	cout << "So, the area will be:" << length * width;
return 0;
}

Well done :p

@Edit:
Another task 4 you :p

Read this:
http://www.cplusplus.com/reference/clibrary/cstdlib/rand/

And do something like:
Code:
Save random number to variable.
Please type number:
User: XXX
if (xxx == variable)
user won the match!
 
PHP:
#include <iostream>
using namespace std;

int main()
{
    while(true){
int length, width;
	cout << "Type a length:";
	cin >> length;
	cout << "\nOkay, the length is: " << length << "\n";


	cout << "\nType a width:";
	cin >> width;
	cout << "\nOkay, the width is:" << width << "\n";

	cout << "\nSo, the area will be:" << length * width << "\n";
}

}

A bit bit better.
 
PHP:
#include <iostream>
using namespace std;

int main()
{
    while(true){
int length, width;
	cout << "Type a length:";
	cin >> length;
	cout << "\nOkay, the length is: " << length << "\n";


	cout << "\nType a width:";
	cin >> width;
	cout << "\nOkay, the width is:" << width << "\n";

	cout << "\nSo, the area will be:" << length * width << "\n";
}

}

A bit bit better.

Definig variables each loop? Suxor :p
Also add screen clearing.
 
Ah, fuck! There's an example XD
It's c++, but same functions, i guess.
 
iostream is the library for input/output reading. input/outputstream

Input means when someone write something / click or whatever while output is when you show something to them :p

Input: cin
Output: cout

Whereas "c" stands for "console"

So, cin = "console input" and cout = "console output"
 
iostream is the library for input/output reading. input/outputstream

Input means when someone write something / click or whatever while output is when you show something to them :p

Input: cin
Output: cout

Whereas "c" stands for "console"

So, cin = "console input" and cout = "console output"

Yaya!

Sality: Thanks for trying to help me :) When I buy a book, I'll learn everything about that :9 But still gonna try to udnerstand it before. It'll just be easier for me :)
As Sality said, but can't make with random numbers xD!

Code:
#include <iostream>
using namespace std;

int main()
{
int lessA, answer;
answer = 7;
       cout << "Type a number between 1-10\n";
       cin >> lessA;
           if(lessA == answer) {
                    cout << "Congratulations! You won.\n";
                    }
           if(lessA > answer) {
                    cout << "Wrong answer. The number is lower.\n";
                    cin >> lessA;                       
                             }
           if(lessA < answer) {
                    cout << "Wrong answer. The number is higher.\n";
                    cin >> lessA;                           
                              }
           system("PAUSE");
return 0;
           
}
 
Last edited:
As I said, keep learning.

Little bit edited version:
Code:
#include <iostream>
using namespace std;

int main()
{
	int lessA, answer, tries;
	answer = 7;
	tries = 2;

	while (tries > 0)
	{
		cout << "You have " << tries << " tries left.";
		cout << "Type a number between 1-10\n";
		cin >> lessA;
		if (lessA == answer)
		{
			cout << "Congratulations! You won.\n";
			tries = 0;
		}
		else if (lessA > answer)
		{
			cout << "Wrong answer. The number is lower.";
			tries--;
		}
		else if (lessA < answer)
		{
			cout << "Wrong answer. The number is higher.";
			tries--;
		}
		system("cls");
	}
	cout << "Thanks for playing :)\n";
	system("PAUSE");
	return EXIT_SUCCESS;
}
 
I got a book called "C++ Programmering" Its very detailed.
I dont know realy if its a english texted version but i nearly can promise that :)
A book i recommend for people that are interested :)
 
Back
Top