loop issue and compile

Write your question here. Can not seem to get a loop to run program again.
1 to run, 0 to end.

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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
 using std::cout;
using std::cin;
using std::endl;


void check_this(int x);

int main()
{

        int i=1;
        int total;//delared total variable
        int in_var;
        const short MAX_N=20;
        bool run_again;


        do(run_again==true);




        {

        cout<<endl<<"What value would you like to stop the sum  over the function x^5 + 10?"<<endl;
        cin>>in_var;


        while (in_var<1|| in_var>MAX_N)
        {
                cout<<"That value is invalid, please enter a value from 1 through "<<MAX_N<<endl;
                cin>>in_var;
        }
                total=0;

        for (int i=1; i<=in_var; i++)//loop statement




                total += i;


                cout<<"The total sum over " <<in_var<< " is  " <<total<<endl;








        cout<<"Would you like to try another value to sum up to?"<<endl<<"Enter 0 for no or 1 for yes.  ";
        cin>>run_again;
        int value;


        else(run_again==false)

        {cout<<endl;}


        }

        return 0;
}
Your program won't compile. In your do-while loop, you missed the while part ;)

If you have further problems, feel free to ask.
Last edited on
Where should I place the while? Right now I am using do(run_again).
Well...like this
1
2
3
4
5
6
7
8
9
10
11
.
.
.
do{

   // execute what you want to repeat as per user's wish in this block
   
}while(userInput == i_want_to_continue);
.
.
.


EDIT:

I just saw that your do is also wrong.

You can code it something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
.
.
int main()
{
   char choice = 'y';
   do{
      /***
       your stuff goes here 
      ***/
   cout << "You want to try again? (Y/N) : ";
   cin >> choice;
    }while(choice == 'y' || choice == 'Y');
}
.
.


I hope that explains.
Last edited on
Topic archived. No new replies allowed.