C/C++ Beginner's Guide and Post Basic Questions here

Abhishek532

Broken In
Joined
Dec 30, 2013
Messages
25
Hi all!


[C++]
I wanted to create something like Menu in the output window /Run in Code::Blocks .Like when I run the code,it should first ask me to input 2 numbers ,then it should ask to do sum,difference,product or division in this format--

Press 1 for Addition
Press 2 for Subtraction
Press 3 for Multiplication
Press 4 for Division

or something like that .Please help

P.S-I'm a beginner actually and I've made programs to calculate multiplication tables,all maths operations and area/perimeter of triangle and square ,so please not-so-advanced code :p :p

Thank you
 

aaruni

The Linux Guy
Joined
Mar 17, 2012
Messages
1,170
you could do simple things like enter 1 for addition, 2 for subtraction, etc (notice I use the word enter, not press, so you can use cin, instead of getchar).

then, you can use simple if-else to direct the control to relevant code.
 

Vignesh B

Youngling
Joined
Dec 9, 2010
Messages
683
You may use the else-if ladder as already posted above, or you may also use the switch statement to use the relevant code.
 

Abhishek532

Broken In
Joined
Dec 30, 2013
Messages
25
Thank you all ! It would be great if someone would give a code related to it so as to help me understand :D
 

kunalht

In the zone
Joined
Sep 7, 2012
Messages
392
Thank you all ! It would be great if someone would give a code related to it so as to help me understand :D


Try yourself first! and then ...... hit spoiler :p

Code:
#include <iostream>

using namespace std;

int main()
{
    int a , b, c,x ;
    cout <<" Enter value of a and b"<< endl;
    cin >> a ;
    cin >> b ;
    cout << "Enter 1 for addition , 2 for suntraction 3 for multiplication & 4 for division!" << endl;
    cin >> x ;
    switch (x)
        {

    case 1:
        c = a + b ;
        cout << c ;
        break;
    case 2:
            c = a - b;
            cout << c ;
            break;
    case 3:
            c = a * b;
            cout << c ;
            break;
    case 4:
            c = a / b;
            cout << c ;
            break;
    default:
            cout  << "Wrong input" << endl;
        }

    return 0;
}
 

tech0freak0

tech is in mah bl00d
Joined
Jan 25, 2013
Messages
82
Eclipse is giving me hard time.....

I can't compile program, i have downloaded Cywin; But it not helping

And gcc is not downloading from equation.com as it giving ftp error.
 

krishnandu.sarkar

Simply a DIGITian
Staff member
Joined
Nov 13, 2007
Messages
4,671
Eclipse is giving me hard time.....

I can't compile program, i have downloaded Cywin; But it not helping

And gcc is not downloading from equation.com as it giving ftp error.

Why don't you simply use Code::Blocks? Or you can even use Visual Studio.
 

srkmish

Ambassador of Buzz
Joined
Mar 14, 2011
Messages
582
Hi friends,

Im learning unix at office. Im enjoying it. I use putty for it. I have downloaded putty in my home computer but am puzzled as to how to use it cuz there is no remote server to login to from my home pc. Is there a workaround for this?
 

Vyom

The Power of x480
Staff member
Admin
Joined
May 16, 2009
Messages
7,046
Im learning unix at office. Im enjoying it. I use putty for it. I have downloaded putty in my home computer but am puzzled as to how to use it cuz there is no remote server to login to from my home pc. Is there a workaround for this?

You use Putty to connect to actual remote machines.
If you want to practice Unix commands/shell programming you have following choices:
1. Use linux distros like Ubuntu
2. Use Live Disk of any distro like Ubuntu
3. Use a program like UWIN which provides a tool on windows to practice Unix commands. A Link. But its trialware so only works for 30 days. First two methods are preferred.
 

Desmond

Destroy Erase Improve
Staff member
Admin
Joined
Apr 9, 2005
Messages
9,616
Best option to learn Unix is Cygwin in windows. Also, you can use MinGW
 

layzee

■■■■■■
Joined
May 12, 2008
Messages
181
Hi friends,

Im learning unix at office. Im enjoying it. I use putty for it. I have downloaded putty in my home computer but am puzzled as to how to use it cuz there is no remote server to login to from my home pc. Is there a workaround for this?

Install VirtualBox and then create a new virtual machine with a new virtual hard disk. Boot into it using a live ISO of any popular GNU/Linux distro like Ubuntu or Fedora, install it to the virtual hard drive and you're done.
 

tech0freak0

tech is in mah bl00d
Joined
Jan 25, 2013
Messages
82
In C language malloc() is a function, right?
I want to see contents of the malloc function i.e behind scene, So i can have a better understanding.
 

aaruni

The Linux Guy
Joined
Mar 17, 2012
Messages
1,170
In C language malloc() is a function, right?
I want to see contents of the malloc function i.e behind scene, So i can have a better understanding.

if its a function in one of the header files, simply open that header file in a text editor and read away!
 
Top