Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7500037
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:02:36+00:00 2026-05-29T20:02:36+00:00

//Writing a letter #include <iostream> using namespace std; int main() { string first_name; //Name

  • 0
//Writing a letter

#include <iostream>
using namespace std;

int main() {
string first_name;      //Name of addressee
string friend_name;     //Name of a friend top be mentioned in the letter
char friend_sex, m, f;  //variable for gender of friend

friend_sex = 0;

cout << "\nEnter the name of the person you want to write to: ";
cin >> first_name;

cout << "Enter the name of a friend: ";
cin >> friend_name;

cout << "Enter friend's sex(m/f): ";    //Enter m or f for friend
cin >> friend_sex;                      //Place m or f into friend_sex

cout << "\nDear " << first_name << ",\n\n"
     << "   How are you? I am fine. I miss you!blahhhhhhhhhhhhhhhh.\n"   
     << "blahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.\n"
     << "Have you seen " << friend_name << " lately? ";

//braces only necessary if there are more than one statement in the if function
if(friend_sex == m) {
    cout << "If you see " << friend_name << ", please ask him to call me.";             
}   //If friend is male, output this
if(friend_sex == f) {
    cout << "If you see " << friend_name << ", please ask her to call me.";
}   //If friend is female, output this

return(0);
}

This is what actually comes out:

Enter the name of the person you want to write to: MOM

Enter the name of a friend: DAD

Enter friend's sex(m/f): m

Dear MOM, 

        How are you? I am fine. I miss you! blahhhhhhhhhhhhhhhhh.
        blahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh.
        Have you seen DAD lately?

This program is simulating a short letter. Outputting a block of words is easy enough, but when I want some conditionals to be placed in the letter, I’m in trouble. Even though I’ve input the friend_sex (m/f) when the program asks me, the output from the if statement does not materialize. Why?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T20:02:41+00:00Added an answer on May 29, 2026 at 8:02 pm

    You’re testing friend_sex against the uninitialized character variable m. You probably want to test against the literal value 'm'. It would be like having an integer variable called seven and expecting it to hold the value 7.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a paper using the ACM template which capitalizes every letter in
I am writing a program that performs different string operations on every letter of
#include <stdio.h> int main (int argc, const char * argv[]) { FILE *fp; fp=fopen(/Users/--------/Desktop/C.txt,
Writing something like this using the loki library , typedef Functor<void> BitButtonPushHandler; throws a
In most cases I'm writing german texts. Most words start with an uppercase letter
I am writing a data warehouse, using MySQL as the back-end. I need to
I am writing a string compare function to sort medical terms that often contain
So I am writing a registration form and I need the display name to
I am writing code to enter a string and convert all its uppercase letters
I am currently writing a distributed system using hazelcast. I have a few questions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.