Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

Basic Cpp ~easy to understand~


ghost's Avatar
0 0

Here are some codes that will help you understand Cpp. i will split this up into two parts. this is the first part.




#include <iostream>
#include <string>

using namespace std;

void main ()
{
	double perc= .62;      //since it has a decimal, use double
	int Tsale= 4600000;     // use int meaning integer  (total Sale)
	int PredSal;
	PredSal= perc *Tsale ;
	cout<<"Predicted East Coast Sales = $"<<PredSal<<endl<<endl;

  
/*  comment *** comment *** comment

cout is used and then the message goes inside the "" ""  then we call PreSal to cout giving the result

*/




	system("pause");
}







#include <iostream>
#include <string>

using namespace std;

void main ()
{
	double AmountoPay; 
	double NumberoPeriod;
	double total;
	AmountoPay=1700.00;
	NumberoPeriod= 26;
	cout<<"Amount of pay per pay period is $"<<AmountoPay<<endl;
	
	cout<<"\nNumber of pay periods per year is "<<NumberoPeriod<<endl;
	total = AmountoPay * NumberoPeriod;
	cout<<"\nThe annual pay is $"<<total<<endl<<endl;
	system("pause");
}




#include <iostream>
#include <string>

using namespace std;

void main()
{
	int number1;
	int number2;
	int number3;
	int average;
	int total;

	cout<<"The Average of Three Numbers\n"<<endl;
	cout<<"Enter Number 1:		";
	cin>>number1;
	cout<<"\nEnter Number 2:		";
	cin>>number2;
	cout<<"\nEnter Number 3:		";
	cin>>number3;

	cout<<"\nNumber 1:	"<<number1<<endl;
	cout<<"Number 2:	"<<number2<<endl;
	cout<<"Number 3:	"<<number3<<endl;
	total=number1+number2+number3;
	average=total/3;
	cout<<"\nAverage: "<<average<<endl;
	cout<<"Total: "<<total<<endl;

	system("pause");
}




#include <iostream>
#include <string>

using namespace std;

void main()
{
	double PurchasePrice;	//purchase price
	double CountySaletTax;	//country sale tax
	double StateSalestax;  //state sales tax
	double TotalSaleTax;	//total sale tax
	PurchasePrice=52;
	CountySaletTax=PurchasePrice * .02;
	StateSalestax=PurchasePrice * .04;
	TotalSaleTax=CountySaletTax + StateSalestax;

	cout<<"On a purchase of $"<<PurchasePrice<<"\n"<<endl;
	cout<<"The county sales tax = $"<<CountySaletTax<<endl<<endl;
	cout<<"The county sales tax = $"<<StateSalestax<<endl<<endl;
	cout<<"the total sale tax = $"<<TotalSaleTax<<endl<<endl;

system("pause");
}





#include <iostream>
#include <string>
#include <iomanip>

using namespace std;

void main()
{
	double MP;		//Meal Price
	double TX; 	//Tax
	double TP;	//Tip
	double TC;	//Total Charge

	
	cout<<"Summary of charges:"<<endl;
	cout<<"--------------------\n"<<endl;
	cout<<"Meal:	";
	cin>>MP;
	TX= MP*.0675;
	TP= (MP+TX)*.15;
	TC= MP+TX+TP;
	cout<<"Tax:	"<<setprecision(2)<<fixed<<TX<<endl;
	cout<<"Tip:	"<<TP<<endl;
	cout<<"Total Charges:	"<<TC<<endl;

	system("pause");
}
	




#include<iostream>
#include<string>

using namespace std;
void main()
{
	double I1,I2,I3,I4,I5; //Item1, Item2, Item3, Item4, Item5
	double SL;	//Subtotal
	double ST;	//Sale Tax
	double TL;	//Total

	cout<<"Item #1:	";
	cin>>I1;
	cout<<"Item #2:	";
	cin>>I2;
	cout<<"Item #3:	";
	cin>>I3;
	cout<<"Item #4:	";
	cin>>I4;
	cout<<"Item #5:	";
	cin>>I5;
	cout<<"---------------------------"<<endl;
	SL= I1+I2+I3+I4+I5;
	ST= SL * 0.06;
	TL= SL + ST;
	cout<<"SubTotal:	"<<SL<<endl;
	cout<<"Sale Taxe:	"<<ST<<endl;
	cout<<"Total:		"<<TL<<endl;
	
	system("pause");
}



markup``````markup


ghost's Avatar
0 0

Wouldn't it have been better to make this into an article and add in some explanations with it? Not just show a code but maybe teach it too


ghost's Avatar
0 0

i could have.

thanx


ghost's Avatar
0 0

no problem, just a little suggestion ^_^


ghost's Avatar
0 0

ASS3 IT NICE TO SEE HOW <iomanip> IS BEEN USED

#include <iomanip>


 cout&lt;&lt;&quot;Tax: &quot;&lt;&lt;setprecision(2)&lt;&lt;fixed&lt;&lt;TX&lt;&lt;endl;


WHERE (2) IS THE DECIMAL PLACES


ynori7's Avatar
Future Emperor of Earth
0 0

these belong in the code bank, not the forums.


ghost's Avatar
0 0

stop posting shit here and post in the code bank and create articles


ghost's Avatar
0 0

thanx,

       I MIGHT...:D

richohealey's Avatar
Python Ninja
0 0

regedit wrote: thanx,

       I MIGHT...:D

What the hell…..?

How did these "codes" help me understand C++

All i understand is that you're a clown.


ghost's Avatar
0 0

richohealey wrote:

What the hell…..?

How did these "codes" help me understand C++

Yeah that's what everyone seems to be saying lol and it doesn't look to different from all the threads like this, just code and no explanation to go along with it…


ghost's Avatar
0 0

i hate to be that guy…

but if you are gonna show code as a tutorial or instructional purpose….

at least comment…

i guess i'm a organized person….


eXXon's Avatar
Member
0 0

alka wrote:

at least comment…

I'm sorry but alka is right.. if you want to teach someone you could have written an article.. or maybe at the very least comment your code..


ghost's Avatar
0 0

Golly, aint that the truth.


yours31f's Avatar
Retired
10 0

WTF is this supposed to be, Im not sure but i think you failed. Miserably.


ghost's Avatar
0 0

thanks for your feedback.

for those that do not understand the basics of cpp, be sure to check out www.cplusplus.com, it helps to read.

Once you understand the basics, YOU should come back to this page and understand what each of these are doing.

I also posted in other langs, so once you understand the basics of cpp, compare them with the others. I MADE THEM SIMPLE TO UNDERSTAND THE LOGIC.

Check out the ones in COBOL, the logic is so simple, there is no way you won't understand them. Then apply the same logic in java,c#,vb.net, and so on…

When i started with programing, i would study the code and then i would go and write my own program with some guidance.

this is phase o 1, if you follow the phases 1 and 2, I assure that you will be able to write good basic programing, and you will learn its fundamentals.

PLEASE FEEL FREE TO POST ANY COMMENTS OR QUESTIONS. :D