Answer to Question #256903 in C++ for Ae Dion

Question #256903

Determine what's wrong in this code and change it.


#include



using namespace std;

int main(){

cout<<"Hello there, please tell me your name?";

char name[50];

cin>>name;

cout<<" Thank you, "< cout<<"Enter 1 or 2\n";

int n;

cin>>n;

if(n==1){

cout<<"True\n";

}

else if(n==2){

cout<<"False\n";

}

else{

cout<<"Invalid\n";

}

cout<<"Enter your birth year:\n";

int year;

cin>>year;

cout<<"Your age is: "<<2021- year<}


1
Expert's answer
2021-10-27T00:26:32-0400
#include <iostream>

using namespace std;

int main() {
  cout<<"Hello there, please tell me your name: ";

  char name[50];
  cin >> name;
  cout << "Thank you, " << name <<". Enter 1 or 2: ";
  int n;
  cin >> n;
  if (n == 1) {
    cout << "True\n";
  }
  else if(n == 2) {
    cout << "False\n";
  }
  else {
    cout << "Invalid\n";
  }

  cout << "Enter your birth year: ";
  int year;
  cin >> year;
  cout << "Your age is: " << 2021 - year << '\n';
  return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS