Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

2.24 Ch 2 Warm up: Variables, input, and casting (C++) (1) Prompt the user to in

ID: 3747695 • Letter: 2

Question

2.24 Ch 2 Warm up: Variables, input, and casting (C++) (1) Prompt the user to input an integer, a double, a character, and a string, storing each into separate variables. Then, output those four values on a single-separated by a space. (2 pts) Note: This zyLab outputs a newline after each user-input prompt. For convenience in the examples below, the user's input value is shown on the next line, but such values don't actually appear as output when the program runs Enter integer: Enter double: 3.77 Enter character: Enter string: Howdy 99 3.77 z Howdy (2) Extend to also output in reverse (1 pt) Enter integer

Explanation / Answer

//Header Files

#include <iostream>
#include <string>

using namespace std;

//Main function
int main()
{
//Declare variables of type integer,char,string and double type
  
int userInt;
double userDouble;
char userChar;
char userStr[10];
  
//Take input from users and store
  
cout<<"Enter integer:"<<endl;
cin>>userInt;
  
cout<<"Enter double:"<<endl;
cin>>userDouble;
  
cout<<"Enter character:"<<endl;
cin>>userChar;
  
cout<<"Enter String:"<<endl;
cin>>userStr;
  
//Print input from users in that order
  
cout<<"In order"<<endl;
cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userStr<<endl;
  
//Print input from users in reverse order
  
cout<<"Reverse order"<<endl;
cout<<userStr<<" "<<userChar<<" "<<userDouble<<" "<<userInt<<endl;

//Cast double into int and Print
userDouble=int(userDouble);
  
cout<<"Cast Double into int and print"<<endl;
cout<<userInt<<" "<<userDouble<<" "<<userChar<<" "<<userStr<<endl;
  
return 0;
}