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

Abhishek532

Broken In
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
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
You may use the else-if ladder as already posted above, or you may also use the switch statement to use the relevant code.
 

kunalht

In the zone
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
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.
 

srkmish

Ambassador of Buzz
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
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.
 

layzee

■■■■■■
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
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
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 Bottom