C++/New

Advertisement


Question
Hi,
I'm very new to C++ and its really confusing, i need our help please........
How do i write a code for a function that prompts the user to enter a character stores the char in a char variables and the function returns the character entered by the user

Answer
Hi ngee

to solve a C++ or any kind of programming problem you have to go step by step

#include<iostream.h>

char func(void); //the function used in the program is declared here

void main() //step1: usual syntax void main
{
//step7: variable to store the value returned from the function
char a;

//step6: call the function to get the char
a = func();

//step8: print the char returned from the function
cout<<a;

}

//step2: a function that returns a char
char func()
{
//step3: a variable to store a char
char ch;    

//step4: for a char from the user
cin>>ch;

//step5: return the char to the calling function
return ch;
}

In case of any doubt please feel free to get back to me.

regards
Joydeep Bhattacharya
http://www.scodz.com

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Joydeep Bhattacharya

Expertise

TSR, Socket and Very Complex Mathematical Problem

Experience

Worked on many OOP projects with design patterns

Organizations
http://www.scodz.com

Publications
http://www.scodz.com

Education/Credentials
Master of Computer Applications

Awards and Honors
Being a proud owner of a website of programming called http://www.scodz.com

Past/Present Clients
http://www.funforu.com http://www.dhoondho.com http://analysingc.50webs.com

©2016 About.com. All rights reserved.