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

  • SEARCH
  • Home
  • 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 7963541
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:37:48+00:00 2026-06-04T05:37:48+00:00

I have been wondering why the code below is giving me different output on

  • 0

I have been wondering why the code below is giving me different output on Windows OS. Meanwhile, the same code works well on Ubuntu.

#include <iostream>
#include <cstring>

using namespace std;

string getname(void);
char getgender(string);
void setinfo(string,char);

int main()
{
    string customer = "";
    char gender;
    do {
        do{
            customer = getname();
        }while(customer =="");
        do{
            gender = getgender(customer);
            cout << "Gender in Main block is: " << gender << endl;
        }while(gender != 'm' && gender != 'f');
        setinfo(customer,gender);
        break;
    }while(1);
    return 0;
}

string getname(void)
{
    string name = "";
    cout <<"Please Enter your Name: " ;
    getline(cin,name);
    if(name == ""){
        cout << "Error: Name cannot be empty" <<  endl;
    }
    return name;
}

char getgender(string name)
{
    char gender;
    string strgender;
    cout << "Male / Female[m/f]: ";
    getline( cin,strgender);
    gender = strgender[0];
    strgender.clear();
    gender = tolower(gender);
    if(gender == 'm' || gender == 'f'){
        cout << "Gender in getgender() is: " << gender << endl;
        return gender;
    }
    else
        cout <<"Error: Must be m/ f" << endl;
}

void setinfo(string customer, char gender)
{
    string prefix;
    if(gender == 'm')
        prefix =  "Mr.";
    else
        prefix = "Ms/Mrs.";
    cout << "Hello " << prefix << " " << customer << endl;
    cout << "Welcome to TOWER HEIGHT" << endl;
}

On my Ubuntu machine, this code works fine. But when I compile and run it on Windows, I get different output and it keeps looping at getgender().

    Please Enter your Name: My Name
    Male / Female[m/f]: m
    Gender in getgender() is: m
    Gender in Main block is: ╕

    Male / Female[m/f]: f
    Gender in getgender() is: f
    Gender in Main block is: ╕

    Male / Female[m/f]:
  • 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-06-04T05:37:50+00:00Added an answer on June 4, 2026 at 5:37 am

    Your getgender() function falls off the end without returning a value when gender is set to an invalid value. This may be causing the compiler to generate bad code for that function; try fixing it by adding a “return 0” to the end.

    You should turn on warnings on your Linux system, incidentally (by using the -Wall compiler flag). That would have made the problem immediately apparent:

    example.cpp: In function ‘char getgender(std::string)’:
    example.cpp:54: warning: control reaches end of non-void function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code similar to the below that I have been
I have been using the block of code below to supposedly stop sql injections.
I have been wondering about the reload() function in python, which seems like it
I have been wondering about the performance of regular expression implementations lately, and have
Something I have been wondering about properties for a while. When you are using
Lately i have been wondering if there is a performance difference between repeating the
I've been hacking around with Ruby a little and I have been wondering if
Hello android designers, 1-I have been wondering. Is it a good design approach to
I ran into this RegExp /[[0]]/ in JavaScript, and have been wondering what it
I have been using Jquery alot lately an was wondering if I should use

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.