#include
using namespace std;
int main ()
{
int thuesuat;
float luong, sothue, luongrong = 0;
cout << "Enter salary amount:";
cin >> luong;
if (luong> 15)
{
sothue = luong * 0.3;
thuesuat = 30;
}
else if (length> = 7)
{
sothue = luong * 0.2;
thuesuat = 20;
}
else
{
sothue = luong * 0.1;
thuesuat = 10;
}
luongrong = luong-sothue;
cout << "Salary =" << luong << endl;
cout << "Income tax" << thuesuat << "% =" << sothue << endl;
cout << "Real wages =" << in << endl;
return 0;
}
Results when running the above code:
Write a C ++ program to enter age and print out the results if the age of the student is not eligible for 10th grade. Know the student's age of entering the 10th grade is 16.
Sample C ++ code:
#include
#include
using namespace std;
int main ()
{
int tuoi;
cout << "Enter student age:" << endl;
cin >> tuoi;
if (tuoi == 16)
{
cout << "Student's age is:" << tuoi << "tuoi." << endl;
cout << "Students are old enough to enter 10th grade!" << endl;
}
else
{
cout << "Student's age is:" << tuoi << "tuoi." << endl;
cout << "Students are not old enough to enter 10th grade!" << endl;
}
return 0;
}
Output result:
Write a C ++ program to enter any integer from the keyboard and print the results to the screen to notify the user of whether the number is greater or less than 100.
Sample C ++ code:
#include
#include
using namespace std;
int main () {
int a;
cout << "Enter integer:" << endl;
cin >> a;
if (a> 100)
{
cout << a << "greater than 100." << endl;
}
else
{
cout << a << "less than 100." << endl;
}
return 0;
}
Output result:
C ++ exercises about IF ELSE 4
Write a C ++ program for users to enter 3 integers and find the largest number of those 3 numbers.
Sample C ++ code:
#include
#include
#include
using namespace std;
int main (int argc, char * argv [])
{
cout << "Enter any 3 numbers:";
int a1, a2, a3, max;
cin >> a1 >> a2 >> a3;
max = a1; // Assume the largest first number
if (max
if (max
cout << "The maximum number of 3 numbers is:" <
return 0;
}
Output result:
Write a C ++ program that ranks students' performance based on midterm test scores and test scores and final exam scores. If:
Sample C ++ code:
#include
#include
#include
using namespace std;
int main (int argc, char * argv [])
{
float a;
float b;
float c;
float dtb;
cout << "Enter test scores, midterm, final grades corresponding:";
cin >> a >> b >> c;
dtb = (a + b + c) / 3;
cout << "Average score is:" <
if (dtb> = 9.0) cout << "Grade A";
else if ((dtb> = 7.0) && (dtb <9.0)) cout << "Class B";
else if ((dtb> = 5.0) && (dtb <7.0)) cout << "Class C";
else if (dtb <5.0) cout << "Class F";
else cout << "Invalid score";
cout << "n";
cout << "Award by TipsMake.com";
return 0;
}
Output result:
Write a C ++ program to find the solution of the quadratic equation ax2 + bx + c = 0. Know that:
Sample code:
#include
#include
#include
using namespace std;
int main ()
{
float a, b, c, d, x1, x2;
cout << "Enter the coefficient a, b, c of the corresponding equation of the second order:" << endl;
cin >> a >> b >> c;
if (! a) {
if (! b)
cout << "Both a and b cannot be equal to 0 in equation ax ^ 2 + bx + c = 0" << "n";
else
{
d = -c / b;
cout << "The equation has a unique solution:" << d << endl;
}
}
else
{
d = b * b-4 * a * c;
if (d> 0)
x1 = (- b + sqrt (d)) / (2 * a);
x2 = (- b-sqrt (d)) / (2 * a);
cout << "First solution x1 =" << x1 << endl;
cout << "Second solution x2 =" << x2 << endl;
}
cout << "Award by TipsMake.com";
return 0;
}
Output result:
Your store accepts to sell products to another company and earn commissions, with commissions according to sales volume as follows:
Write a C ++ program to calculate the commission you will receive based on sales.
Sample C ++ code:
#include
#include
using namespace std;
int main ()
{
long int doanhso;
hoahong float;
cout << "Total sales:" << endl;
cin >> doanhso;
if (doanhso <= 100)
{
hoahong = doanhso * 5/100;
cout << "With total sales is" << sales << ",";
cout << "the commission received is" << hoahong;
}
else if (doanhso <= 300)
{
hoahong = doanhso * 10/100;
cout << "With total sales is" << sales << ",";
cout << "the commission received is" << hoahong;
}
else if (doanhso> 300)
{
hoahong = doanhso * 20/100;
cout << "With total sales is" << sales << ",";
cout << "the commission received is" << hoahong;
}
cout << "n";
cout << "Award by TipsMake.com";
return 0;
}
Output result:
Write a C ++ program to calculate the phone bill for a household with the following parameters:
Sample C ++ code:
#include
#include
using namespace std;
int main ()
{
long int sophut, phi = 0;
float tong;
const int phicodinh = 25000;
cout << "Number of minutes to call in the month:";
cin >> sophut;
if (sophut> 200)
phi = (sophut-200) * 200 + 150 * 400 + 50 * 600;
else if (sophut> 50)
phi = (sophut-50) * 400 + 50 * 600;
else
phi = sophut * 600;
tong = phi + phicodinh;
cout << "You called" << sophut << "minutes." << endl;
cout << "Phone amount to be paid is << << endl;
cout << "Award by TipsMake.com";
return 0;
}
Output result:
If you are learning Python and Java programming, don't ignore the Python exercises and Java exercises.