C++ First Software: How To Make Simple Lovemeter In C++ (lesson 1)

C++ is one of the vast programming language ever. Many operating system are developed via C++.  In my experience it is quite similar to java. Since i learnt java first , It was not much hard for me to shift to this language. The thing is we need have algorithm,concepts, know to use data structure’s and correct methods declaration. You can use any c++ compilers but i recommend Microsoft Visual Studio 2005/2008/2010. I use Microsoft Visual Studio 2010. You can find it from Microsoft website. Download and install this compiler. You can try this link http://www.microsoft.com/download/en/details.aspx?id=5555 .

First application : Lovemeter

Lovemeter is something like imaginary so it doesn’t matter how you code it. I am just using addition, division and multiplication of the username lengths. Easy for you to understand.  Create new win32 project from Microsoft Visual Studio. Be sure it is an empty project. Create new .cpp file named helloworld.cpp and paste the following code

Source Codes

#include <iostream>
#include <string>
#include <sstream>

using namespace std;

int main ()
char ans;
do {
system(“TITLE Lovemeter By Pradeepsofts.com”);
string firstname, secondname, again;
cout <<“Welcome to lovemeter by www.pradeepsofts.com\n”;
cout << “Please enter first name: \n”;
getline (cin, firstname);
cout << “Please enter second name: \n”;
getline (cin, secondname);
float a=firstname.length();
float b=secondname.length();
float c=a + b;
float p= (a/c)*100 ;
cout << firstname  <<” loves “<< secondname << p << ” percent\n”;
cout <<“Do you want to calculate love again? (y/n) : “;
cin >>ans;

while((ans !=’N’)&&(ans !=’n’));
return 0;

This is very simple we just appended some codes in main method. char ans holds  the character value.  I just used Do, While statement. system(“CLS”) clears the screen. system(“TITLE text”) helps to set the text to the respective window.   string firstname, secondname, again – declaration of the string variable. cout is the echo tag for c++. It should be followed by << and double inverted comma and a semi colon. If we have to print the variable value then we just dont need to put double inverted comma. Scrolling below you can see variables printed and they dont require double inverted comma. Printing the specific texts we need double inverted comma.   getline (cin, firstname) – This piece of code is to get the input of the user and store it to variable firstname. We could use INT instead of FLOAT but unfortunately c++ division required floating values i,e. 20/30 returns value 0 but 20.00/30.00 returns correct output. We just made some calculations.   float a=firstname.length() – This is the syntax to get length of the string  value stored in the variable. We could use INT here but Division requires value in 00.00 format and float data type makes floating values.   cin >>ans;  gets the input from users and store the value, While the value is y or Y or something else the program loops to first line of main method. Else if it is equal to n or N then the program ends. I have uploaded a sample Compiled executed (.exe) file. You can down it below and this is the output of the coding above. We will learn putting icons and making colorful GUI in upcoming lessons.

download sample love meter

Download c++ sample love meter

Hope this helped you as a simple start. We will have lots of tutorials in upcoming time taking from simple calculations to Great GUI networking applications.

Author: pradeep

Share This Post On

Submit a Comment