Basic Cpp ~easy to understand~
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
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