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

Write a C++ program that accepts a number followed by a space and then the lette

ID: 3883263 • Letter: W

Question

Write a C++ program that accepts a number followed by a space and then the letter. If the letter following the number is an "i" then the program is to treat the number entered as a dimension in inches and convert the number to an equivalent length in centimeters and display a suitable message indicating the conversion. If the letter following the number is a "c", then the program is to treat the number entered as a dimension in centimeters and convert the number to the equivalent length in inches, and display a suitable message indicating the conversion. The if, else if statement must be used.

Explanation / Answer

#include<iostream>

#include<string.h>

using namespace std;

int main(){

double n;

char str[100];

double val=0;

cout<<"ENter a number and letter followed by space :";

cin>>n;

cin>>str;

if(strcmp(str,"i") == 0){

val = n*2.54;

cout<<"Conversion from inches to centimeters "<<val<<endl;

}

else if(strcmp(str,"c")==0){

val = n/2.54;

cout<<"Conversion from centimeters to inches "<<val<<endl;

}else{

cout<<"Invalid conversion "<<endl;

}

return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote