i was told something and it screwed me up!

This is a discussion on i was told something and it screwed me up! within the C++ Programming forums, part of the General Programming Boards category; i have this huge book called "teach yourself C++" and i posted a sample code on this other forums of ...

  1. #1
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343

    i was told something and it screwed me up!

    i have this huge book called "teach yourself C++" and i posted a sample code on this other forums of a C programmer. and he told me i was typing C! ?????????? C!?!?!?!?!?! i want to learn C++, tell me if this is wrong:
    Code:
    #include <iostream>
    #include <stdlib.h>
    
    // callin the fuctions
    int menu();
    int calc();
    int calcadd();
    int calcsub();
    int calcmult();
    int calcdiv();
    /* here is the main deal, the design and the goto the menu function
    thingy, you know */
    int main()
    {
    // wicked ViperVision design!
    cout << "###              ### ###              ###" << endl;
    cout << " ###            ###   ###            ###" << endl;
    cout << "  ###          ###     ###          ###" << endl;
    cout << "   ###        ###       ###        ###" << endl;
    cout << "    ###      ###         ###      ###" << endl;
    cout << "     ###    ###           ###    ###" << endl;
    cout << "      ###  ###             ###  ###" << endl;
    cout << "       ######               ######" << endl;
    cout << "        ####  iper           ####  ision          v0.5" << endl << endl;
    cout << " Console Based Computer Utensile Program " << endl << endl;
    // end the wicked design :(
    system("pause");
    menu();
    }
    /* notice how my main is really short? cuz it dont need too much here!
    here is our main menu function */
    int menu()
    {
    int selut;
    cout << "please select a utility to use! " << endl << "(0 = Quit, 1 = QuickCalc)" << endl;
    cin >> selut;
    if (selut == 1) {
    cout << "you chose to use the calculater" << endl;
    calc();
    } else if (selut == 0) {
    cout << "you chose to quit, c'ya!" << endl;
    system("pause");
    return 0;
    }
    }
    int calc()
    {
    int calcwhat;
    cout << "what do you plan to do?" << endl << "(1 = Add, 2 = Subtract, 3 = Multiply, 4 = Divide, 5 = back)" << endl;
    cin >> calcwhat;
    if (calcwhat == 1) {
    calcadd();
    } else if (calcwhat == 2) {
    calcsub();
    } else if (calcwhat == 3) {
    calcmult();
    } else if (calcwhat == 4) {
    calcdiv();
    } else if (calcwhat == 5) {
    menu();
    } else {
    cout << "you typed something strange, redo" << endl;
    calc();
    }
    }
    int calcadd()
    {
    int addone;
    int addtwo;
    int product;
    cout << "the first number: ";
    cin >> addone;
    cout << endl;
    cout << "the second number: ";
    cin >> addtwo;
    cout << endl;
    product = addone + addtwo;
    system("pause");
    cout << addone << " + " << addtwo << " = " << product << endl;
    system("pause");
    calc();
    }
    int calcsub()
    {
    int subone;
    int subtwo;
    int product;
    cout << "the first number: ";
    cin >> subone;
    cout << endl;
    cout << "the second number: ";
    cin >> subtwo;
    cout << endl;
    product = subone - subtwo;
    system("pause");
    cout << subone << " - " << subtwo << " = " << product << endl;
    system("pause");
    calc();
    }
    int calcmult()
    {
    int mulone;
    int multwo;
    int product;
    cout << "the first number: ";
    cin >> mulone;
    cout << endl;
    cout << "the second number: ";
    cin >> multwo;
    cout << endl;
    product = mulone * multwo;
    system("pause");
    cout << mulone << " * " << multwo << " = " << product << endl;
    system("pause");
    calc();
    }
    int calcdiv()
    {
    int divone;
    int divtwo;
    int product;
    cout << "the first number: ";
    cin >> divone;
    cout << endl;
    cout << "the second number: ";
    cin >> divtwo;
    cout << endl;
    product = divone / divtwo;
    system("pause");
    cout << divone << " / " << divtwo << " = " << product << endl;
    system("pause");
    calc();
    }
    this DOS program compiles and works.
    is this C or C++? cuz i dont know if my book is teaching me C++ or C, and C# i dont want to learn at all.

  2. #2
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    maybe its just me but for anything other then the main i would have used voids.

    like

    void display
    void menu

    int main


    Also i didn't see(may have overlooked it) a return value for main:

    return 0;

  3. #3
    Bios Raider biosninja's Avatar
    Join Date
    Jul 2002
    Location
    South Africa
    Posts
    765
    Well, as far as I've heard, If you're using cin or cout, it's C++

  4. #4
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    return 0 will quit the function and ultimately quit the program to the best of my knowledge so far but here is where my return 0 is. where the option to quit is.

    Code:
    } else if (selut == 0) {
    cout << "you chose to quit, c'ya!" << endl;
    system("pause");
    return 0;
    }
    and as for the return anything else, i dont. its just simple cout'ed here:
    Code:
    cout << mulone << " * " << multwo << " = " << product << endl;

  5. #5
    RoD
    RoD is offline
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    My mistake, and thats C++ : )

  6. #6
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    hey hey, thats alright, and thanx for answering my question. ill show MaxxJag this hes the one that told me this was C.
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21