Wow what compiler is that? That's annoying that there is no text with it. Post your current code and try out another compiler. At least it gives you the line numbers, look at the settings and see if there's something you can change.

I think you have missunderstood the use of return....

Yes, thank you. I had told him to just eliminate them and I hadn't really explained why. The only reason you're lucking out and getting the functions to run is that whatever follows the return is evaluated before the return actually happens (so I could write return 2*3-6; and it would return 0).

so how do you propose i go to these functions if i shouldnt be using return...also is that why i couldnt put a second set of returns under the first set, because with the if statement they worked fine, but once i put in a new if statement inside of it, the returns started throwing errors

Just call the function outright:

multiplication();
division();
etc.

Calling them without something to accept the return value(i.e., mulitplication(); vs. int x = multiplication();) discards that value, but you aren't using them anyway.

@joncsa, its actually devc++ which i think im supposed to be useing wxdevc++ if i remember correctly? someone was saying that devc++ is really old, but yeah i tried deleting the return and it still give me the errors, wtffff is going on

Honestly, skip over the wxdevc++ and grab Code::Blocks. Much better, updated all the time, newer version of the compiler included.

Post what you currently have, since you've obviously made some changes

okay now that i have codeblocks we have new issues its saying system is declared, so i take that as i cant do windows system calls? also thanks for the advice these errors are much easier to understand, so am i gonna have to use conio.h and use getch_ instead of system calls?

for system("PAUSE") etc? you can use windows.h

yeah i actually posted that before i included that...jumping the gun i guess, okay lemme review this and see what problems im still having

|125|error: expected ')' before ';' token|
||=== Build finished: 1 errors, 0 warnings ===|


and heres the code as is

#include<iostream>
#include<conio.h>
#include<windows.h>


using namespace std;
//so this is where i have just the interface, its not really "variables"
//like the one poster mentioned
//also i havent got to class yet...



int addition()
{
    double a1;
    double a2;
    string s2;
    system("CLS");
    cout << "This will add two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double adding= (a1 + a2);
    cout << "The sum is ";
    cout << adding;
    cout << endl; //above code obviously just adds 2 numbers
    system("CLS");
    cout << "Would you like to perform another operation?\n";
    cout << "Press y or n";
    cin  >> s2;
}

int multiplication()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will multiply two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double multi= (a1 * a2);
    cout << "The product is ";
    cout << multi;
    cout << endl;

    system("pause");
    return 0;
}

int subtraction()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will subtract two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double subtracting= (a1 - a2);
    cout << "The difference is ";
    cout << subtracting;
    cout << endl;

    system("pause");
    return 0;
}

int division()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will find the mean of two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double division= (a1/a2);
    cout << "The quotient is ";
    cout << division;
    cout << endl;

    system("pause");
    return 0;
}

int main()
{
    //strings that will be used in the program
    string s1;
    string s2;
    do
    {
        cout << "What math operation would you like to perform?\n";
        cin  >> s1;


        if((s1=="Division") || s1==("division") || (s1=="/"))
        {
                division();   //these work
        }
        else if((s1=="Addition") || (s1=="addition") || (s1=="+"))
        {
                addition(); //same
        }
        else if((s1== "Subtraction") || (s1=="subtraction") || (s1=="-"))
        {
                subtraction(); //same
        }
        else if((s1== "Multiplication" || s1=="multiplication") || (s1=="*"))
        {
                multiplication();
        }
        else
        {
        cout << "It seems you have mistyped something, try again\n";
        system("pause");
        system("CLS");
        main();
        }
    }while((s2!="Y") || (s1!="y");
}

First try to learn what errors means,then you can google them.

your error says that expect " ) " before " ; "

means you forgot to close a parenthese,give a closer look at line 125 :P

okay well now it compiles but entering n doesnt end the loop....

everything is voided except main.... still wont close out when i type an n... is anyone seeing a problem

Maybe you should try taking you call to main() out. It's still in there and now it's actually causing you a problem! Your code never reaches the end of the loop because you're calling main and circumventing it.

Good move getting Code::Blocks. It's got a nice interface to a debugger (gdb) that will be useful.

for system("PAUSE") etc? you can use windows.h

A more portable solution (and one that isn't platform dependent) is to put

cin.ignore();
cin.get();

at the very end of your code. Sometimes the stream gets clogged with extra characters and it gets run through like a stop sign at the mall, so you'd have to flush the input buffer using the techniques in the sticky thread of the forum. If there's just a stray '\n' or nothing in the stream, it works just fine.

Something to consider.

yeah i've heard of these, i guess there from the conio.h library, or "header" if you will, but what to they mean exactly, and where do you propose i put them? cin.ignore seems redundant since ignoring user input would be redundant? why ask for something if your going to ignore it? and then cin.get? what are you getting? i thing that command means terminate the program if im not mistaken?

No, they are not from conio.h. Conio is outdated and non-standard. Some people do still use getch from conio, but for those reasons, they shouldn't. get and ignore are part of iostream. You put them where you would put system("pause");

You need the ignore because sometimes you'll have a situation like:

int n;
cin >> n;
//put in 10 and hit enter, the 10 is stored in the int, but where is the '\n' from enter stored?  Nowhere, it's left in the input "stream."

So if you follow the above by

cin.get()

the get will pull in the next character in the stream, which is the '\n' and so your program doesn't wait for a key, it's already got one. Putting in the ignore will sop up that extra character so the pause will work. Occasionally, you have to hit an extra enter with the ignore statement in there, but that's the only downside. The upside is that your code will be portable (on systems where there is no "pause" command) and there are issues of security (say all of the programs on your machine with sensitive information use system("pause"), then if someone places a nefarious "pause" program in the same directory, then there's trouble. Not exactly an issue with a college assignment, but something of which to be aware.

okay so i know that "\n" means null but all i can figure out that it means is the same as "void" also what would i use for a system("cls"), making this program run really clean cut and professional looking is one of my key goals, also, this isnt for a college class, hah i wish it i was in school for this, then i wouldnt be asking such dumb questions, but hey thats for this fall, untill then i hang out here and try to learn, so besides being confused by null and needing a substitute for system("cls") the program still doesnt exit when you enter "n" or "N", any ideas? i think this is gonna be going on for a while, guess its not such a simple question :/

^desregard that \n is newline \0 is null...jesus im slipping up, okay so would the procedure for what im trying to achieve be

cout << "Press Any Key To Continue";
cin.get();
cin.ignore();

?

cin.ignore comes first. Post up your latest code with the changes and I'll take a look

okay but not only do i need a portable substitute for system("cls"), it still isnt responding to it when you type in "N" current code is

#include<iostream>
#include<conio.h>
#include<windows.h>


using namespace std;
//so this is where i have just the interface, its not really "variables"
//like the one poster mentioned
//also i havent got to class yet...



int addition()
{
    double a1;
    double a2;
    string s2;
    system("CLS");
    cout << "This will add two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double adding= (a1 + a2);
    cout << "The sum is ";
    cout << adding;
    cout << endl; //above code obviously just adds 2 numbers
    system("CLS");
    cout << "Would you like to perform another operation?\n";
    cout << "Press y or n";
    cin  >> s2;
}

int multiplication()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will multiply two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double multi= (a1 * a2);
    cout << "The product is ";
    cout << multi;
    cout << endl;

    system("pause");
    return 0;
}

int subtraction()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will subtract two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double subtracting= (a1 - a2);
    cout << "The difference is ";
    cout << subtracting;
    cout << endl;

    system("pause");
    return 0;
}

int division()
{
    double a1;
    double a2;
    system("CLS");
    cout << "This will find the mean of two numbers\n";
    cout << "Please enter the first number:";
    cin >> a1;
    cout << "Please enter the second numeber:";
    cin >> a2;
    double division= (a1/a2);
    cout << "The quotient is ";
    cout << division;
    cout << endl;

    system("pause");
    return 0;
}

int main()
{
    //strings that will be used in the program
    string s1;
    string s2;
    do
    {
        cout << "What math operation would you like to perform?\n";
        cin  >> s1;


        if((s1=="Division") || s1==("division") || (s1=="/"))
        {
                division();   //these work
        }
        else if((s1=="Addition") || (s1=="addition") || (s1=="+"))
        {
                addition(); //same
        }
        else if((s1== "Subtraction") || (s1=="subtraction") || (s1=="-"))
        {
                subtraction(); //same
        }
        else if((s1== "Multiplication" || s1=="multiplication") || (s1=="*"))
        {
                multiplication();
        }
        else
        {
        cout << "It seems you have mistyped something, try again\n";
        cin.get();
        cin.ignore();
        main();
        }
    }while((s2!="Y") || (s2!="y"));
}

swap 122 with 121, like jonsca told you.

else
        {
        cout << "It seems you have mistyped something, try again\n";
        cin.ignore();
        cin.get();
        main();
        }
    }while((s2!="Y") || (s2!="y"));

still no change, still no clear screen :/

changed this

}while((s2!="Y") || (s2!="y"));

to this

}while((s2=="Y") || (s2=="y"));

but now y and n return the stopcode....i dont even know how to return stop codes?

why you call main fuction?the programs are working from top to bottom.

to understand better what you want to do and what your program does,start reading it from top,when you encounter multiplication() for example means you enter that fuction and comes back to main when reach the last " } " of the multiplication fuction,when you call the main() you create a 2nd copy of your main,and i cant understand exactly why you want to do that.

how you see it at your mind?

i dont know personaly other way for clear screen except system("CLS");

the cin.get and cin.ignore was to use instead of system("PAUSE")

I had told you to move lines 29-31 out of the function and into the main() and between lines 7 and 8 of your second listing. If there's no input being taken, s2 is just uninitialized the way that you have it.

You're listening to about every third piece of advice from ntrncx or myself, and this is hindering this process considerably. We've both told you not to call main, and there it is, over and over again.

i dont know personaly other way for clear screen except system("CLS");

There's really no portable way to do this, AFAIK. People that develop text-based applications will tell you that clearing is more of a hindrance to the user than a help, but if it's part of your assignment, you may have to use it.

okay but not only do i need a portable substitute for system("cls"),

No you don't. There is no reason for a console program to clear the screen. It's actually annoying to the user.


And this was mentioned a couple times, just not strong enough for you to hear it, so I'll try:

Never, NEVER, NEVER call main() ! NEVER! It is not a function per se/ It is the entry point to your program from the O/S. If you need to start the program over, use a loop.

And get rid of conio.h . It's not standard and you don't need anything from it.

Lastly, what do you need windows.h for? What are you using from it? Whatever it is, you probably shouldn't be using it, either.


PS -- true to form when someone says my problem is easy, it becomes a mega-thread. The word easy is the forum equivalent of radiation on the animal kingdom that creates monsters. And saying incredibly is just turning up the Roentgens! Easy my butt... :icon_twisted:

commented: Thank you. +6
commented: wondering the same while flipping the pages...:) +1

okay because i was trying to encapsulate everything in one function but i guess i could make the math statements just double statments? i mean i didnt know what i was doing was SO taboo that nobody even knows why i do it, real reality check haha, uhm as for windows.h i need to still use system("cls"), and conio.h was because i was going to use getchar() or getchar_ but i never got around to it so ill just delete that, but still, shouldnt somebody be able to look into the windows.h file and see how they make the screen clear? i have a hard time believe that theres no way to clear a terminal screen when people can make 3D games, and piplining encryption software, bottom line i dont believe for a minute that you can build a spaceship without first knowing what combustion is. ill play around with this code and try to make everything encapsulate inside main(); just to keep on par with what you guys recommend and also to shorten the length.

i have a hard time believe that theres no way to clear a terminal screen

That's not what we've been saying. There is no standard way to do it that is portable across all platforms. If you don't want to listen to my advice or to WaltP (who's been doing this kind of thing for a couple of years now), there are plenty of other people who will tell you the same thing.

try to make everything encapsulate inside main();

Leave your functions (addition, subtraction, etc.) as they are, though. Don't try to jam those into main.

commented: Couple of years? Hmmmm... :o) +15

as for windows.h i need to still use system("cls"), and conio.h was because i was going to use getchar() or getchar_ but i never got around to it so ill just delete that, but still, shouldnt somebody be able to look into the windows.h file and see how they make the screen clear?

There is no screen clear in C++. The fact is that C++ was not designed with the screen and keyboard in mind. It was designed to be a general computing language. The I/O design was never meant to be robust. Simply adequate. As for looking into windows.h to see how to clear the screen, do it. It's right there on your computer in the include directory for your compiler. Find it and post it here...

i have a hard time believe that theres no way to clear a terminal screen when people can make 3D games, and piplining encryption software,

That's because people wrote special code packages to interface with your graphics card, the screen, keyboard, mouse, etc. They are special and in no way part of the C++ language design.

bottom line i dont believe for a minute that you can build a spaceship without first knowing what combustion is.

Really? Therein lies your difficulty. You are concerned about combustion, and the spaceship we are designing works on anti-gravity.

oh okay but arent headers just ways to assoiciatite a way of doing something with what you want to call it? so by that theory there should be a semi-standard way to clear the screen? but more importantly, im getting a red line but the debugging window isnt coming up in codeblocks? what does that mean

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.