SlideShare une entreprise Scribd logo
1  sur  2
1. Write a program in C++ that prompts the user to input an integer between 0 and 31. If the
number is less than or equal to 5, the program should output the number; otherwise, it should
output A for 6, B for 7, C for 8...and Z for 31. (Hint: Use the cast operator, static_cast( ), for
numbers >= 6.)
Solution
#include <iostream>
using namespace std;
int main()
{
int number;
cout << "Enter the number (between 0 and 31): "; //Prompt user to enter number
cin>>number;
if(number>=6)Â Â //if number is greater than or equal to 6 print A for 6, B for 7....
cout <<"Output:"<<static_cast<char>('A'+number-6);
else if(number<=5)
cout<<"Output:"<<number;
}
/*
Output
1st run output:
Enter the number (between 0 and 31): 3
Output:3
2nd run output:
Enter the number (between 0 and 31): 7
Output:B
*/

Contenu connexe

Similaire à 1- Write a program in C++ that prompts the user to input an integer be.docx

Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
nayakq
 

Similaire à 1- Write a program in C++ that prompts the user to input an integer be.docx (14)

C#.net
C#.netC#.net
C#.net
 
PCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdfPCA-2 Programming and Solving 2nd Sem.pdf
PCA-2 Programming and Solving 2nd Sem.pdf
 
PCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docxPCA-2 Programming and Solving 2nd Sem.docx
PCA-2 Programming and Solving 2nd Sem.docx
 
10 template code program
10 template code program10 template code program
10 template code program
 
Core programming in c
Core programming in cCore programming in c
Core programming in c
 
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdfC# 6Write a program that creates a Calculation ClassUse the foll.pdf
C# 6Write a program that creates a Calculation ClassUse the foll.pdf
 
Best C Programming Solution
Best C Programming SolutionBest C Programming Solution
Best C Programming Solution
 
Ch7
Ch7Ch7
Ch7
 
Ch7
Ch7Ch7
Ch7
 
comp1
comp1comp1
comp1
 
C Language Programming Introduction Lecture
C Language Programming Introduction LectureC Language Programming Introduction Lecture
C Language Programming Introduction Lecture
 
Programming fundamentals
Programming fundamentalsProgramming fundamentals
Programming fundamentals
 
In C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docxIn C Programming create a program that converts a number from decimal.docx
In C Programming create a program that converts a number from decimal.docx
 
Qust & ans inc
Qust & ans incQust & ans inc
Qust & ans inc
 

Plus de cwayne3

How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
cwayne3
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
cwayne3
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
cwayne3
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
cwayne3
 

Plus de cwayne3 (16)

I am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docxI am trying to create a code that will show an error if someone puts a.docx
I am trying to create a code that will show an error if someone puts a.docx
 
I need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docxI need a short code that is ritten in Visual basic that explains that.docx
I need a short code that is ritten in Visual basic that explains that.docx
 
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docxi Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
i Encapsulation} ra te compilation is to achieve encapsulation- How to.docx
 
How would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docxHow would you characterize Web 2-0- Describe the set of technologies t.docx
How would you characterize Web 2-0- Describe the set of technologies t.docx
 
How would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docxHow would you describe the macroeconomic --worldview-- of David Ricard.docx
How would you describe the macroeconomic --worldview-- of David Ricard.docx
 
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx1-Put the ionic compounds in order of smallest to largest lattice ener.docx
1-Put the ionic compounds in order of smallest to largest lattice ener.docx
 
10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx10- which of the following should be the first step in reviewing he fi.docx
10- which of the following should be the first step in reviewing he fi.docx
 
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
1-8(x+2)-4- 12 Please show steps for pointsSolution 1-8(x+2)-4- 12.docx
 
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
10- Dinitrogen trioxide is a molecular compound t-f 11- Lithium phosph.docx
 
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx10) Which species acts as the nucleophile in the reaction of 1-butene.docx
10) Which species acts as the nucleophile in the reaction of 1-butene.docx
 
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
1-) What are the tax concepts involved in completing the Form 1040- Ex.docx
 
1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx1-) Which of the following accounting concepts do accountants and audi.docx
1-) Which of the following accounting concepts do accountants and audi.docx
 
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx1- Why does the initially formed copper hydroxide precipitate dissolve.docx
1- Why does the initially formed copper hydroxide precipitate dissolve.docx
 
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
1- Which substance CANNOT have dipole-dipole forces between its molecu.docx
 
1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx1-Write an algebraic expression to represent each verbal expression-.docx
1-Write an algebraic expression to represent each verbal expression-.docx
 
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
1- Which planet has the least cloudiness- b) Earth c) Mars d) Jupiter.docx
 

Dernier

The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 

Dernier (20)

Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 

1- Write a program in C++ that prompts the user to input an integer be.docx

  • 1. 1. Write a program in C++ that prompts the user to input an integer between 0 and 31. If the number is less than or equal to 5, the program should output the number; otherwise, it should output A for 6, B for 7, C for 8...and Z for 31. (Hint: Use the cast operator, static_cast( ), for numbers >= 6.) Solution #include <iostream> using namespace std; int main() { int number; cout << "Enter the number (between 0 and 31): "; //Prompt user to enter number cin>>number; if(number>=6)Â Â //if number is greater than or equal to 6 print A for 6, B for 7.... cout <<"Output:"<<static_cast<char>('A'+number-6); else if(number<=5) cout<<"Output:"<<number; } /* Output 1st run output: Enter the number (between 0 and 31): 3 Output:3 2nd run output: Enter the number (between 0 and 31): 7 Output:B
  • 2. */