Write a program that does the following Ask the user to inpu

Write a program that does the following: Ask the user to input a floating point number, f First convert f to an integer number, n, Please output a message based upon the value of n: Please use both if-then statement and switch-case statement to complete this task.

Solution

#include <iostream>
using namespace std;

int main()
{
   float f;
   int n;
  
   cout<<\"\ Input a floating point number : \";
   cin>>f;
  
   n = (int)f; // integer cast
  
   cout<<\"\ n = \"<<n;
  
   switch(n%7)    // remainder operator % is used
   {
       case 0:
       case 6: cout<<\"\ This is a weekend\";
               break;
       case 1:
       case 2:
       case 3:
       case 4:
       case 5: cout<<\"\ This is a workday\";
               break;
       default: cout<<\"Invalid day\";
              break;
   }
   return 0;
}

output:

 Write a program that does the following: Ask the user to input a floating point number, f First convert f to an integer number, n, Please output a message base

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site