Preview 3 out of 10 Flashcards
In this program, you have to make use of the switch statement. The average life expectancy (in 
hours) of a lightbulb based on the bulb’s wattage is listed in the table below
In this program, you have to make use of the switch statement. The average life expectancy (in 
hour...
#include <iostream>
using namespace std;
int main()
{
 int watts,
 life;
 cout<<"Enter the watts of a bulb: ";
 cin>>watts;
 switch(watts)
 {
 case 25:
 life=25000;
 break;
 case 40:
 case 60:
 life=1000;
 break;
 case 75:
 case 100:
 life=750;
 break;
 }
 if(watts==25||watts==40||watts==60||watts==75||watts==100)
 cout<<"The life expectancy of a light bulb with "<<watts<<" watts is "<<life<<" hours."<<endl;
 else
 cout<<"the life expectancy in hours is not defined in the range for the watts entered."<<endl;
 return 0;
}
Suppose we want to input and validate the age of students that qualify for an internship, as well as 
the final mark obtained for the examination, in a while loop. To qualify, the student should be 
younger than 30 with a final mark of more than 65%. Read in values util a suitable candidate is 
found. Display appropriate messages, wheter successful or not. The variable names are age and 
finalMark respectively. Complete the while loop below. You only have to write down the completed 
while loop
Suppose we want to input and validate the age of students that qualify for an internship, as well as...
while(age>30||finalMark<65) 
{ 
 cout<<”Candidate not suitable.”<<endl; 
 cout<<”Enter age: “; 
 cin>>age; 
 cout<<”Enter final mark: “; 
 cin>>finalMark; 
}
Include the for loop below in a small program and complete the program. The loop should be 
executed 10 times. Do not change the for loop below. Compile and run your program to see for 
yourself that it works. You do not have to submit this program and output.
Include the for loop below in a small program and complete the program. The loop should be 
executed...
#include <iostream>
using namespace std;
int main()
{
 int i=0;
 while(i<=10)
 {
 if (i<5 && i!=2)
 cout<<"X";
 i++;
 }
 return 0;
}