Errors in Script

Hello I am new to scripting (very new) and I am encountering many issues that I am having trouble identiying.

The script is as follows:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <cmath>
using namespace std;

class verify{
    public:
        int ver(int x){
                while ( ! (cin >> x)){
                    cout << "Error. Try again: ";
                    cin.clear ();
                    cin.ignore (1000, '\n');
            }
        }
}

int main(){
    int input;
    double due, pay, stilldue, absvalue, pay2, stilldue2;
    ver obj;
    cout << "Each Movie is $10." << endl;
    cout << "Please enter in how many you want:";
    cin >> input;
    obj.ver(input);
    due = input * 10;
    cout << "$" << due << " is due." << endl;
    cout << "Please insert money:";
    cin >> pay;
    obj.ver(pay);
    stilldue = due - pay;


   while(stilldue > 0){
        cout << "Please insert $" << stilldue << endl;
        cin >> pay2;
        obj.ver(pay2);
        stilldue =  stilldue - pay2;
    }
    if(stilldue < 0){
        absvalue = abs (stilldue);
        cout << "Here is $" << absvalue << " back" << endl;
        cout << "thank you";
    }
    else if (stilldue == 0){
        cout << "thank you";
    }
    return 0;
}


I keep getting these errors:

||In member function 'int verify::ver(int)':|
|13|warning: no return statement in function returning non-void|
|5|error: new types may not be defined in a return type|
|5|note: (perhaps a semicolon is missing after the definition of 'verify')|
|16|error: two or more data types in declaration of 'main'|
||=== Build finished: 2 errors, 1 warnings ===|

I've done some research but I still cannot understand what I'm doing wrong. Sorry, I haven't messed with coding much before, any help or explanations would be appreciated.
Last edited on
I'll pick one...

1
2
3
class verify{
    public:
        int ver(int x){


says you want ver(int x) to return an int, but you arn't.
I assume you want to return the value of x after checking?
Place return x; after the while loop.
If you don't want to return a value use void ver(int x)
Last edited on
Stick a semi-colon after your class definition, like this:
1
2
3
4
5
6
7
8
9
10
class verify{
    public:
        int ver(int x){
                while ( ! (cin >> x)){
                    cout << "Error. Try again: ";
                    cin.clear ();
                    cin.ignore (1000, '\n');
            }
        }
}; // SEE THIS SEMI-COLON? YOU NEED IT 



ver obj; This says "make me an object of type ver, and call it obj". What exactly is an object of type ver? There is no such object. Did you mean this?
verify obj;


As an aside, that's not a script. C++ is not a scripting language. We call it a program.
Last edited on
Ok thanks, i managed to get rid of all the errors and warnings but now, when the program asks for any kind of input, i have to enter it in twice for the script to continue running. how would i go about fixing this? Here's the updated program:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include <cmath>
using namespace std;

class verify{
    public:
        int inp;
        void verifyin(int x){
                inp = x;
                while ( ! (cin >> inp)){
                    cout << "Error. Try again: ";
                    cin.clear ();
                    cin.ignore (1000, '\n');
            }
        }

};

int main(){
    int input;
    double due, pay, stilldue, absvalue, pay2, stilldue2;
    verify obj;
    cout << "Each Movie is $10." << endl;
    cout << "Please enter in how many you want:";
    cin >> input;
    obj.verifyin(input);
    due = input * 10;
    cout << "$" << due << " is due." << endl;
    cout << "Please insert money:";
    cin >> pay;
    obj.verifyin(pay);
    stilldue = due - pay;


   while(stilldue > 0){
        cout << "Please insert $" << stilldue << endl;
        cin >> pay2;
        obj.verifyin(pay2);
        stilldue =  stilldue - pay2;
    }
    if(stilldue < 0){
        absvalue = abs (stilldue);
        cout << "Here is $" << absvalue << " back" << endl;
        cout << "thank you";
    }
    else if (stilldue == 0){
        cout << "thank you";
    }
    return 0;
}
also, the point of the "verifyin" function is to check if what is entered is an integer. I want it to loop until what the user inputs has the appropriate return type(hence, the while loop). I just didnt want to have to retype the while loop each time the program tries to get user input. i figured this would make the program "more efficient."
Topic archived. No new replies allowed.