what is wrong with this code?

the last } seems to be the problem but why?


/*AvRAGE a average program*/
#include <iostream>
using namespace std;

int main(void)
{
system("TITLE AvRAGE++");
system("COLOR 3");
char cDoagain;
double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;
double daverage = 0.0;
do
{
system("CLS");
cout << "Welcome, to AvRAGE++!" <<endl;
cout << "Please enter 3 numbers that you would like to average:"<<endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage =(dnumber1 + dnumber2 + dnumber3) /3;
//need to loop program
cout << "the average for those numbers are:"<< daverage <<endl <<endl;
system("PAUSE");
cout << "Would you like to start again? (Y/N)" <<endl;
cin >> cDoagain;
while (cDoagain == 'y' || cDoagain == 'y')

return 0;
}
Try putting a ; behind the while statement.

while (cDoagain == 'y' || cDoagain == 'y');
i think you forget a } after
cin >> cDoagain;
the do-while is still open in your code
closed account (z05DSL3A)
Venged,
As you have not use the code tags [1] I can't say much about your code formatting, but if you format you code along the line of the following you can easily see that the opening brace { on line 16 dose not have a matching closing brace } on line 31 (as was pointed out by akmalnuernberg).

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
/*AvRAGE a average program*/
#include <iostream>
using namespace std;

int main(void)
{
    system("TITLE AvRAGE++");
    system("COLOR 3");
    char cDoagain;
    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    do
    {
        system("CLS");
        cout << "Welcome, to AvRAGE++!" <<endl;
        cout << "Please enter 3 numbers that you would like to average:"<<endl;
        cin >> dnumber1;
        cin >> dnumber2;
        cin >> dnumber3;

        daverage =(dnumber1 + dnumber2 + dnumber3) /3;
        //need to loop program
        cout << "the average for those numbers are:"<< daverage <<endl <<endl;
        system("PAUSE");
        cout << "Would you like to start again? (Y/N)" <<endl;
        cin >> cDoagain;

    while (cDoagain == 'y' || cDoagain == 'y')

    return 0;
}


for what it is worth, my personal preference for braces is to have them on a line of there own and have another level of indentation for the code that comes between them. eg:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
do
{
    if(...)
    {
        if(...)
        {
            ...
        }
    }
    else
    {
         ...
    }
} while(...)  // the exception to the brace on it own line     


This way it is easy to match up braces and see what is controlling the block of code you are working on. Some people prefer the following style:

1
2
3
4
5
6
7
8
9
do{
    if(...){
        if(...){
            ...
        }
    }else{
        ...
    }
} while(...)  


HTH

[1]How to: Put code into your postings
http://www.cplusplus.com/forum/articles/1624/
Last edited on
That code looks frighteningly similar to one of the tutorial videos on YouTube.
Topic archived. No new replies allowed.