Help on getting started with C++

We were given a very basic introduction to C programming.

Today we were set a task in labs to use Microsoft Visual Studio 2008 and use C++.

The question on the task was :

Test the following expressions, where a, b and c are all integers and a and b have been assigned the values 8 and 9, respectively. You need to explain in the report what the value of each of the following expressions is and if the value of a or b changes, you need to give their new value.
· c = b/a
· a = b
· a = b = 5
· c = ++a + b--

I'm a completely beginner so have ABSOLUTELY no idea where to start. Does anyone have any notes on the basic commands on C++, because I'm completely stuck. Please note I'm not looking for the answer, rather help so I may write the programme myself.

I think it should look something like the following please correct me if I'm wrong!

#include stdio.h

void main (void)

int a, b, c;

a = 8;
b = 9;
c = b/a;

printf (c=b/a);

Whilst on the topic, what does the printf command do, the scanf command?

Any and all help much appreciated!!

Replies

  • MaRo
    MaRo
    Black_Rose
    · c = b/a
    · a = b
    · a = b = 5
    · c = ++a + b--
    a, b & c are integers..

    a = 8, b = 9;

    c = b/a;

    c = 9 / 8 = 1.125

    Since c is an integer, its floating point precision will be deducted, means int datatype doesn't take the digits after the decimal point.

    If you want the floating point precision use another datatype for c like float or double.

    & the flow goes as following:

    a = b; // the value of b replaces the value of a, now a = 9;

    a = b = 5; // now 5 replaces the values of a & b now both equal 5

    c = ++a + b--;

    ++ means incrementing the value of the variable by 1
    -- means decrementing the value of the variable by 1

    but their place in the next to the value differ the time the operation occur, if the they're on the left side the operation occur then do the instruction (line).

    means a & b now equal 5, ++a = 6, b-- = 4, but b won't decrement till the line is done.

    So, c = (++a) 6 + (b--) 5;
    c = 11;
    b = 4; //after the operation is done.


    Black_Rose
    #include stdio.h

    void main (void)

    int a, b, c;

    a = 8;
    b = 9;
    c = b/a;

    printf (c=b/a);
    Whilst on the topic, what does the printf command do, the scanf command?
    this suppose to show the value of c.

    but the printf() function isn't declared right.

    printf("%d",c) OR printf("%d",b/a)

    printf() shows the value of strings, now you want to show an integer so we use "%d" to show the value of c & you can't assign a value "c=b/a" in printf().

    scanf() takes input from user, like:
    int n;
    scanf("%d",&n);
    this waits for user input & press "Enter" button then put the value in "&n"

    &n : is the address of variable n in the memory, the bits value of assigned to its address, that's why we dont just put scanf("%d",n).

    & the "%d", means read it as an integer.


    I hope this is helpful for your query, feel free to ask and you can know more #-Link-Snipped-# & there are plenty of tutorials on a web search for "C++ tutorials"
  • Black_Rose
    Black_Rose
    Maro, thank you! You've been extremely helpful. I got the first program running, I just can't get the console to remain open, which command will keep the window open after execution and how do I output my result, would I be correct in assuming I should use printf (%d, c) ?
  • MaRo
    MaRo
    - You can add function getch(); or scanf(); to keep control for your application

    - printf() prints strings, strings in programming always surrounded with double quotations " string " .. so, it's printf("%d",c);
  • Black_Rose
    Black_Rose
    Maro Thanks alot! I handed in an ace report and I learned plenty.

You are reading an archived discussion.

Related Posts

Mumbai: The free access to automated teller machines (ATMs) of any bank will be closed from October 15 as the third-party ATM usage would carry a cap on the withdrawal...
Computer Science Key concepts (NEW) BIOS (bask input/output system) :-A collection of software codes built into a PC that handle some of the fundamental tasks of sending data from one...
The popularity of Gmail in India cannot be denied, but even we were a bit surprised by a new report that stated it has already gone past Yahoo! Mail as...
The free e-mail client from the makers of Firefox makes an excellent choice for homes and personal use. Here are few tips to make a pro at using it. Access...
Cyber criminals are now more organized While Virus writers were once doing their dubious deeds for fun, they are now a more organized group who trade services. Eugene V. Kaspersky,...