[Release] Simple Program

Posts 1–6 of 6 · Page 1 of 1
[Release] Simple Program
All it does is compare string size/length. The book I'm reading (C++ Primer) wanted me to make it, so here you are. Source is included lol

Virustotal. MD5: 48a4661deac3c927584c21df220341b9
String.zipattachment deleted · 12 downloads before removal
Well your program works perfect, but your form is a little off:
Instead of this:
Code:
using std::string;
using std::cout;
using std::cin;
using std::endl;
Most ppl would just use
Code:
using namespace std;
But I don't know how your book teaches you so I won't press my point.

Also it is "bad practice" to right if statements like this:
Code:
if (input1 == input2)
		cout << "The strings are the same size. \n\n" << endl;
	if (input1 > input2)
		cout << "String 1 is bigger. \n\n" << endl;
	if (input1 < input2)
		cout << "String 2 is bigger. \n\n" << endl;
It would be better to write it like this:
Code:
if (input1 == input2)
		cout << "The strings are the same size. \n\n" << endl;
	else if (input1 > input2)
		cout << "String 1 is bigger. \n\n" << endl;
	else if (input1 < input2)
		cout << "String 2 is bigger. \n\n" << endl;
Again if you havent learned about else if statements I won't pressure you ur book will cover it in due time, but there are a couple of good reasons to use else if statements:

It Creates faster code at run time. When you use else if statements and an evaluation proves true for 1 if the subsequent else if statements would not be executed. In your code unnecessary evaluations would still be carried on after a preceding if statement proves true. While speed may not be a big concern for a small program like yours, these little slow-downs add up in larger programs and can cause noticeable differences at runtime. The best way to keep this from happening later on is to practice it now when your just learning it. Because its hard to remember the little details like this when ur working on a large project if you don't already know them inside and out.

Ok well good code and everything btw if you want to see something cool try this. Choose option 1. Type 20 a's for the first string and 1 "z" for the second string. String 2 will be longer because when you compare the size of strings it compares their values lexicographically (that's alphabetically) Just so you know its the alphabetical order and NOT the physical size (in memory) of the string.

Here's my edited version of your program: Hope u don't mind ;P
String.rarattachment deleted · 5 downloads before removal
Quote Originally Posted by why06 View Post
Well your program works perfect, but your form is a little off:
Instead of this:
Code:
using std::string;
using std::cout;
using std::cin;
using std::endl;
Most ppl would just use
Code:
using namespace std;
But I don't know how your book teaches you so I won't press my point.

Also it is "bad practice" to right if statements like this:
Code:
if (input1 == input2)
		cout << "The strings are the same size. \n\n" << endl;
	if (input1 > input2)
		cout << "String 1 is bigger. \n\n" << endl;
	if (input1 < input2)
		cout << "String 2 is bigger. \n\n" << endl;
It would be better to write it like this:
Code:
if (input1 == input2)
		cout << "The strings are the same size. \n\n" << endl;
	else if (input1 > input2)
		cout << "String 1 is bigger. \n\n" << endl;
	else if (input1 < input2)
		cout << "String 2 is bigger. \n\n" << endl;
Again if you havent learned about else if statements I won't pressure you ur book will cover it in due time, but there are a couple of good reasons to use else if statements:

It Creates faster code at run time. When you use else if statements and an evaluation proves true for 1 if the subsequent else if statements would not be executed. In your code unnecessary evaluations would still be carried on after a preceding if statement proves true. While speed may not be a big concern for a small program like yours, these little slow-downs add up in larger programs and can cause noticeable differences at runtime. The best way to keep this from happening later on is to practice it now when your just learning it. Because its hard to remember the little details like this when ur working on a large project if you don't already know them inside and out.

Ok well good code and everything btw if you want to see something cool try this. Choose option 1. Type 20 a's for the first string and 1 "z" for the second string. String 2 will be longer because when you compare the size of strings it compares their values lexicographically (that's alphabetically) Just so you know its the alphabetical order and NOT the physical size (in memory) of the string.

Here's my edited version of your program: Hope u don't mind ;P
Yea i've still got a ways to go so it hasnt taught me things like else if, namespace std, etc. It's all in due time tho
Cool simple program... keep practicing maybe one day you make hacks!!
Lol i can make hacks, the problem is i can ONLY make hacks >.>
Quote Originally Posted by m4c4r0ni3z View Post
Lol i can make hacks, the problem is i can ONLY make hacks >.>
Agreed. Making game hacks is a lowly existence as a programmer, no matter how good u r.
Posts 1–6 of 6 · Page 1 of 1
This thread is closed for replies.

Similar Threads

Tags for this Thread

Need help?