that Butputs tntuu) value in day that ranges from 0 to 6, with 0 being Sunday. 2
ID: 3738705 • Letter: T
Question
that Butputs tntuu) value in day that ranges from 0 to 6, with 0 being Sunday. 2 Extend the Switch statement in Exercise 1 so that it outputs "Error" if the value 1. Write a Switch statement in day is not in the range of 0 through 6. from Saturday and working backward to Sunday order, starting on Wednesday and going through Tuesday. user fails to enter a correct value, the loop outputs an error message and then repeats 3. Write a For loop that outputs the days of the week, each on a separate line, starting srbeutsthe days of the week n forwad 5. Write a Do-While loop that prompts for and inputs a user entry of "Y" or "N". If the the request for the user to enter the value. 6. Write a code segment that adds up the positive integers, starting at 1, until the sum equals or exceeds a value read from the keyboard, and then prints the last integer add to the sum. Use a Do-While loop to do the summing.Explanation / Answer
As you did not mention the programming language, I am using C++.
Q:1
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter number: ";
cin >> n;
switch(n){
case 0:
cout << "Sunday ";
break;
case 1:
cout << "Monday ";
break;
case 2:
cout << "Tuesday ";
break;
case 3:
cout << "Wednesday ";
break;
case 4:
cout << "Thursday ";
break;
case 5:
cout << "Friday ";
break;
case 6:
cout << "Saturday ";
break;
default:
cout << "Wrong number ";
break;
}
return 0;
}
Q:2
#include <iostream>
using namespace std;
int main()
{
int n;
cout << "Enter number: ";
cin >> n;
int sum = 0;
for(int i = 1; i < n; i++)
sum += i;
cout << "The final sum " << sum << endl;
return 0;
}
**Comment for any further queries.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.