errors in a do while loop with functions

while (Repeat(char again) == true);

when i run that line of code, i get this error
expected primary expression before char

it's a do while loop that runs the main function while the boolean Repeat(char again); is true.

any help would be greatly appreciated.
You want to call the 'Repeat' function sending it as a parameter the 'again'?

Then you shouldn't use the Repeat(char again) syntax. This is only for declaration of the function. To call it you have to use Repeat(again)

 
while (Repeat(again) == true);


Hope that helps.
thanks,

that helped a little, but now i have a bug in the calculator itself.
basically, it takes both inputs in but doesn't return an output.
rather, it waits for another input, and then it asks for the repeat, and the input for the repeat does nothing.

here's the code
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
    cin >> dOne;
    cin >> cOperation;

    if (cOperation == '+'){
        cin >> dTwo;
        double Addition(double dFirst, double dSecond);
    }
    else if (cOperation == '-'){
        cin >> dTwo;
        double Subtraction(double dFirst, double dSecond);
    }
    else if (cOperation == '*'){
        cin >> dTwo;
        double Multiplication(double dFirst, double dSecond);
    }
    else (cOperation == '/');{
        cin >> dTwo;
        double Division(double dFirst, double dSecond);
    }


    cout << "Do you need more help?" << endl;
    cin >> again;
}
while (again == 'y');

    return 0;
}


here are the functions
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

//addition function
double Addition(double dFirst, double dSecond)
{
    cin >> dTwo;
    cout << (dOne + dTwo);
}

//subtraction function
double Subtraction(double dFirst, double dSecond)
{
    cin >> dTwo;
    cout << (dOne - dTwo);
}

//multiplication function
double Multiplication(double dFirst, double dSecond)
{
    cin >> dTwo;
    cout << (dOne * dTwo);
}

//division function
double Division(double dFirst, double dSecond)
{
    cin >> dTwo;
    cout << (dOne / dTwo);
}
This code declares the function, doesn't actually call it:
double Subtraction(double dFirst, double dSecond);
You must put this code where you want to declare the functions.

You call the functins with parameters dFirst and dSecond but you dont use those variables... You use other not defined in the function (except they are global).
To call a function (ex Addition) you should use double result = Addition(dOne, dTwo);
with that you declare a new variable double type named result that has as a value the return of the function Addition.(You should put return statements in the functions, except it is declared s void)

Hope that helps

i have one more problem

the do while loop

at the end i ask the user if he needs any help in the form of a cout statement.
then i ask for his input and the do part runs while the variable is equal to y

however, when i run the program, it goes backwards and ends.

here's the code:
1
2
3
4
5
6
7
8
9
10
11
12
int main()
{
do{...
cout << "/nDo you need more help?"
cin >> cRepeat;
}
while (cRepeat == 'y');

return 0;
}

What do you mean "when i run the program, it goes backwards and ends" ?
instead of asking if you need for help and taking the input
it takes the input then asks if you need more help
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <fstream>
#include <string>

using namespace std;

int main() {
 string sRepeat = "";

 do {
  cout << "Do you need anymore help? ";
  getline(cin, sRepeat);
 } while ((sRepeat == "y") || (sRepeat == "Y"));


return 0;
}


Inputing just a single char isn't ideal. If someone inputs more than 1 char you get unexpected behaviour.
thanks, but i managed to fix the problem a little bit
now instead of asking if you need more help automatically, it just waits for you to input something, and then it asks if you need help. after that, if you input y, it will repeat, and if you input anything else, it will quit.

thanks for the suggestion though.

i tried your code but it didn't change the situation.
Topic archived. No new replies allowed.