0% found this document useful (0 votes)
2K views5 pages

If Else Statement

The document provides solutions to 5 C++ programming problems that use if-else statements to output different results based on integer inputs or comparisons. The problems include comparing two numbers, grading a test score, checking voter eligibility by age, determining a training grade level, and calculating mileage costs. Each problem is solved with a short code sample that uses if-else statements to output the appropriate result.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views5 pages

If Else Statement

The document provides solutions to 5 C++ programming problems that use if-else statements to output different results based on integer inputs or comparisons. The problems include comparing two numbers, grading a test score, checking voter eligibility by age, determining a training grade level, and calculating mileage costs. Each problem is solved with a short code sample that uses if-else statements to output the appropriate result.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

IF ELSE STATEMENT 1.

. Create a C++ program that will input two integer numbers and will output if the first is greater, less than or equal to the second integer. Solution: #include<iostream.h> int n1,n2; int main() { cout<<"Input first integer number:"; cin>>n1; cout<<"Input second integer number:"; cin>>n2;

if (n1<n2) { cout<<"first number is less than the second number"; } else if (n1>n2) { cout<<"first number is greater than the second number"; } else { cout<<"first number is equal to the second number"; } system ("PAUSE"); return 0; }

2. Create a C++ program that will input the test score and will output the grade.

Given the following:

Test Score Grade 90-100 80-89 70-79 60-79 A B C D E

Solution: #include<iostream.h> int t; int main() { cout<<"Enter your test score:"; cin>>t; if (t>=90) { cout<<"Your Grade is an A"; } else if (t>=80) { cout<<"Your Grade is a B"; } else if (t>=70) { cout<<"Your Grade is a C"; } else if (t>=60) { cout<<"Your Grade is a D"; } else { cout<<"Your Grade is a E"; } system ("PAUSE"); return 0; }

59 below

3. Create a C++ program that will input age and will output if you can vote. Solution: #include<iostream.h> int age; int main() { cout<<"Input your age:"; cin>>age; if ( age >= 18) { cout<<"YOU CAN VOTE!!!!!"; } else { cout<<"SORRY YOU CAN'T VOTE"; } system ("PAUSE"); return 0; }

4. Create a C++ program that will input the training grade and will output the training grade level. Solution: #include<iostream.h> int grade; int main() { cout<<"Input the Training Grade Level:"; cin>>grade; if ( grade >= 90) { cout<<"Best Level"; } else if ( grade >=80 ) { cout<<"Good Level"; } else { cout<<"Needs Improvement"; } system ("PAUSE"); return 0; }

5. Write a program so that if the clerk enters the number of miles, the program would display the total price owed. Where: Mileage is less than 100 = 0.25 Mileage is more than 100 = 0.15

Solution: #include<iostream.h> int miles; float tp; int main() { cout<<"Enter Number of Miles:"; cin>>miles; if ( grade >= 100) { tc=miles x 0.15; } else { tc=miles x 0.25 } cout<<The Total Cost is:<<tc<<endl; system ("PAUSE"); return 0; }

You might also like