Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,237 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,126 people online right now. Registration is fast and FREE... Join Now!




Very confusing compiler error. (C++)

 
Reply to this topicStart new topic

Very confusing compiler error. (C++)

Aspokia
post 10 Mar, 2008 - 02:53 PM
Post #1


New D.I.C Head

*
Joined: 10 Mar, 2008
Posts: 3

I'm using:
Windows + Cygwin (GCC Compiler)
So my source goes like this
(I didn't write notes yet... so bear with me...)
CODE
#include <iostream>
using std::cout;
using std::cin;
int x;
int y;
int z;
char tpyeOfAction;
char toContinue;
char yes;
int process1(x)
{
    cout << "Enter number to add to " << x << ".";
    cin >> y;
    z = (x+y);
    return z;
}
int process2(x)
{
    cout << "Enter the number to subtract from " << x << ".";
    cin >> y;
    z = (x-y);
    return z;
}
int process3(x)
{
    cout << "Enter the number to multiply " << x << " by.";
    cin >> y;
    z = (x*y);
    return z;
}
int process4(x)
{
    cout << "Enter the number to divide " << x << " by.";
    cin >> y;
    z = (x/y);
    return z;
}
int process5(x)
{
    cout << "Are you sure you want to square " << x << "?";
    cin >> yes;
    if (yes ="yes")
    {
        z = (x*x);
        return z;
    }
    if (yes ="y")
    {
        z = (x*x);
        return z;
    }
    else
    {
        return 0;
    }
}
int main()
{
    cout << "Welcome to calculator, when you'd like to begin, simply enter a number, and press enter (or return).";
    cin >> x;
    cout << "Now, to Add type: 'ADD' or +\nTo Subtract, type: 'MINUS' or -\nTo Multiply tpye: 'MULTIPLY' or * \nTo Divide type: 'DIVIDE' or /\nTo square, type: @ (SHIFT + #2).";
    cin >> typeOfAction;
    if (tpyeOfAction= "ADD" or "+")
    {
        process1(x);
    }
    if (typeOfAction= "MINUS" or "-")
    {
        process2(x);
    }
    if (typeOfAction= "MULTIPLY" or "*")
    {
        process3(x);
    }
    if (typeOfAction = "DIVIDE" or "/")
    {
        process4(x);
    }
    if (typeOfAction = "@")
    {
        process5(x);
    }
    else
    {
        return 0;
    }
    return 0;
}


The point of this is to:
Ask for initial number, 'x'
Ask for process to use on number (for example: "ADD")
Ask for second number to affect first 'y'
Return Answer.
SO.
I tell it to compile the source,
and it comes up with a list of errors
"11: error: ecpected ',' or ';' before '{' token
18: error: ecpected ',' or ';' before '{' token
25: error: ecpected ',' or ';' before '{' token
32: error: ecpected ',' or ';' before '{' token
39: error: ecpected ',' or ';' before '{' token"
This is... weird, to say the least.
I made 'Hello world!' Program and this didn't happen...
Anyway
There are more weird errors.
"64: error 'process1' cannot be used as a function
68: error 'process2' cannot be used as a function
72: error 'process3' cannot be used as a function
76: error 'process4' cannot be used as a function
80: error 'process5' cannot be used as a function"
I included a picture,
a couple errors have been resolved since.
Again this is weird.
Well, I'm new to C++ so I don't have a clue at to where to go with this...
Anyway, thank you.
And btw, if you see any bugs in my source please tell me.


Attached File(s)
Attached File  IMAGE.bmp ( 664.12k ) Number of downloads: 8
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 10 Mar, 2008 - 03:02 PM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,015



Thanked 171 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


Some of your statements are not proper C++. Check your if statements. Here is an example...

cpp

// This is not right format
if (typeOfAction= "MINUS" or "-")

// Should look like this
if ((typeOfAction == "MINUS") || (typeOfAction == "-"))


Notice the use of the double equal sign for comparisons and the pipes || which represents Or. Also notice that the variable has to be compared against each individual string.

I also notice you have a misspelling on your if statement where you are comparing "Add". You misspelled "typeOfAction" (inversed the y and the p).

You also define your functions to have return values. So when you call then you must store the return value.

cpp

int answer = process5(x);


So fix these errors and see what else you get popping up in the way of errors. smile.gif

This post has been edited by Martyr2: 10 Mar, 2008 - 03:02 PM
User is online!Profile CardPM

Go to the top of the page

letthecolorsrumble
post 10 Mar, 2008 - 03:06 PM
Post #3


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


Also each of the function definitions should be changed from

int process1(x)

to

int process1(int x). smile.gif

Welcome to </dream.in.code> Have a great time here smile.gif

This post has been edited by letthecolorsrumble: 10 Mar, 2008 - 03:18 PM
User is offlineProfile CardPM

Go to the top of the page

zmikeb
post 10 Mar, 2008 - 03:34 PM
Post #4


New D.I.C Head

*
Joined: 1 Mar, 2008
Posts: 27

CODE
#include <iostream>
#include <string>
using namespace std;
int x;
int y;
int z;
string typeOfAction;
string toContinue;
string yes;
int process1(int x)
{
    cout << "Enter number to add to " << x << ".";
    cin >> y;
    z = (x+y);
    return z;
}
int process2(int x)
{
    cout << "Enter the number to subtract from " << x << ".";
    cin >> y;
    z = (x-y);
    return z;
}
int process3(int x)
{
    cout << "Enter the number to multiply " << x << " by.";
    cin >> y;
    z = (x*y);
    return z;
}
int process4(int x)
{
    cout << "Enter the number to divide " << x << " by.";
    cin >> y;
    z = (x/y);
    return z;
}
int process5(int x)
{
    cout << "Are you sure you want to square " << x << "?";
    cin >> yes;
    if (yes =="yes")
    {
        z = (x*x);
        return z;
    }
    if (yes == "y")
    {
        z = (x*x);
        return z;
    }
    else
    {
        return 0;
    }
}
int main()
{
    cout << "Welcome to calculator, when you'd like to begin, simply enter a number, and press enter (or return).";
    cin >> x;
    cout << "Now, to Add type: 'ADD' or +\nTo Subtract, type: 'MINUS' or -\nTo Multiply tpye: 'MULTIPLY' or * \nTo Divide type: 'DIVIDE' or /\nTo square, type: @ (SHIFT + #2).";
    cin >> typeOfAction;
    if (typeOfAction == "ADD" || typeOfAction == "+")
    {
        cout << process1(x);
    }
    else if (typeOfAction == "MINUS" || typeOfAction == "-")
    {
        cout << process2(x);
    }
    else if (typeOfAction == "MULTIPLY" || typeOfAction == "*")
    {
        cout << process3(x);
    }
    else if (typeOfAction == "DIVIDE" || typeOfAction == "//")
    {
        cout << process4(x);
    }
    else if (typeOfAction == "@")
    {
       cout << process5(x);
    }
    else
        {
            system("PAUSE");
        return 0;
    }
    system("PAUSE");
    return 0;
}


This took some serious editing, man. I really suggest that you go through a c++ tutorial like www.cplusplus.com. You should go and learn the basics of c++. If you have any questions about what I did, just send me a message. =)
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 10 Mar, 2008 - 03:46 PM
Post #5


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


Oh zmikeb, you ruined all the fun Martyr2 was going to have teaching the beginner, and we are deprived of one of his code ninja one-liners. tongue.gif lol

This post has been edited by letthecolorsrumble: 10 Mar, 2008 - 03:47 PM
User is offlineProfile CardPM

Go to the top of the page

zmikeb
post 10 Mar, 2008 - 04:21 PM
Post #6


New D.I.C Head

*
Joined: 1 Mar, 2008
Posts: 27

QUOTE(letthecolorsrumble @ 10 Mar, 2008 - 04:46 PM) *

Oh zmikeb, you ruined all the fun Martyr2 was going to have teaching the beginner, and we are deprived of one of his code ninja one-liners. tongue.gif lol


oops......my bad

This post has been edited by zmikeb: 10 Mar, 2008 - 04:30 PM
User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 11 Mar, 2008 - 07:40 AM
Post #7


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 421


My Contributions


Martyr2, How are you getting a syntax-colored code quote?



I knew i should have learned html....sad.gif
lol
User is offlineProfile CardPM

Go to the top of the page

letthecolorsrumble
post 11 Mar, 2008 - 07:48 AM
Post #8


Student of The Sun

Group Icon
Joined: 7 Nov, 2007
Posts: 550



Thanked 1 times
My Contributions


[*code=cpp] for cpp codes

[*code=java] for java codes
User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 12 Mar, 2008 - 12:56 AM
Post #9


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 421


My Contributions


Thanks, lolzers didn't know that.
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/21/08 09:42PM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month