URGHH!!!

Pages: 12
Hello iam new to using c++, it is a rather fasicanting program but it is really annoying.Iam was watching a tutorial on youtube.As far as i know i typed everything right from this video

[/u]http://www.youtube.com/watch?v=nziy2_U5JQI/u]

Here is what i typed in c++


#include<iostream>
using namespace std;

int main(void)
{
double dnumber1 = 0.0;
double dnumber2 = 0.0;
double dnumber3 = 0.0;
double daverage = 0.0;

cout << "please enter 3 numbers: " << endl;
cin >> dnumber1;
cin >> dnumber2;
cin >> dnumber3;

daverage = (dnumber1 + dnumber2 + dnumber3) / 3

cout << "the average of the numbers are: " << daverage << endl << endl;

system("pause");
return 0;

}


Here are the errors that happened.

C:\Dev-Cpp\Test.cpp In function `int main()':
18 C:\Dev-Cpp\Test.cpp expected `;' before "cout"

I don't know what those mean can some one help?
Take out void in between the brackets after main and put a semi colon on the end of the line where you write out the average.
Last edited on
closed account (Lv0f92yv)
I think the void in main(void) can stay, I don't see his compiler complaining about that and I'm fairly confident it just explicitly tells the compiler that there will be no arguments to the function.

The complaint is about that missing semicolon, as MottMan said.
daverage = (dnumber1 + dnumber2 + dnumber3) / 3


that needs a >> ; << at the end

daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

this code should work :)

Desh is correct, leaving the parameters of main empty is the same thing as int main(void)

the second one is just more explicit(and unnecessary : P)
ok now it at least has the window pop up but now when ever i press something it closes out.
Last edited on
Type in three numbers, then [enter]. You should see the average value.
the program is fine..just put a ; after the declaration where you calculate the daverage..just like mahertamim did above..and one more thing..if you intend to use double you don.t need to make
1
2
3
4
double dnumber1 = 0.0;  // =0 it is just fine.
double dnumber2 = 0.0;  //0 or 0.0 or 0.000000 it is the same
double dnumber3 = 0.0;
double daverage = 0.0;


closed account (Lv0f92yv)
ok now it at least has the window pop up but now when ever i press something it closes out.


Try using a getchar(); at the end of your program, before main() returns.

This tells your program to wait for a character to be sent to the input stream (typically from the command line).

hey i got it!!!
:D

thanks guys *cries* hugs and kisses for everyone!!!

Also, iam goning to be posting here very frequently.
sooo... prepare for some drama!!!

EDIT:NEVER it stopped working again.
Last edited on
Looking forward to it sailor, it seems as though you are as far into C++ as I am, so maybe with us two noobs posting problems we can learn from eachother!
@desh: that doesn't work either.

I have it the same way the guy does. After putting the semi colon next to the 3.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include<iostream>
using namespace std;

int main()
{
    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    cout << "please enter 3 numbers: " << endl;
    cin >> dnumber1;
    cin >> dnumber2;
    cin >> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

    cout << "the average of the numbers are: " << daverage << endl << endl;

    cout << "Press ENTER to exit\n";
    cin.get();
    return 0;
}


That should work as I just ran it myself.

Oh, and try using [code] tags around any of your source. [ code ]CODE IN HERE[ /code ] Just don't put those spaces. Highlighting your source and clicking the source code button (the right of the text box, mouse over for name) will do the same.
Last edited on
I tried it and it didn't do anything.

Why did it work for the other guy with out using that?

Where do i put the code thingies?And do i put them with or with out that extra thing you put?
I tried it and it didn't do anything.

Why did it work for the other guy with out using that?


Okay, double up the cin.get() then...

1
2
3
4
5
    cout << "Press ENTER to exit\n";
    cin.get();
    cin.get();
    return 0;
}


The [ code ] goes at the beginning, and the [/ code] goes at the end of your code.
the thing still isn't working.

where is the begging and where is the start of the code?
because when i try it i get a bunch of errors.
So what EXACTLY are you having problems with? Just compiler errors? Can you post them?
iam don't know.

i just tried to compile and run the way i had it it does this

http://i575.photobucket.com/albums/ss197/sailornaruto39/error.jpg

I try your way with out [code] it does nothing

but with code it gives a bunch of errors.
Last edited on
Oooooohh, talk about miscommunication. The [ code] tags are for the forums. Keeping that in mind, you may want to reread my previous post about it.

Anywho, that is odd that it skips the entire piece of code. Try compiling and running this:

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
#include <iostream>

using namespace std;

int main()
{
    double dnumber1 = 0.0;
    double dnumber2 = 0.0;
    double dnumber3 = 0.0;
    double daverage = 0.0;

    cout << "please enter 3 numbers: " << endl;
    cin >> dnumber1;
    cin >> dnumber2;
    cin >> dnumber3;

    daverage = (dnumber1 + dnumber2 + dnumber3) / 3;

    cout << "the average of the numbers are: " << daverage << endl << endl;

    cout << "Press ENTER to exit\n";
    cin.get();
    cin.get();
    return 0;
}


If that still doesn't work, you may want to reinstall your IDE. You may also want to switch to Code::Blocks which is free and much better than Dev C++.
Last edited on
closed account (Lv0f92yv)
Also consider Eclipse C++ (my personal favorite).

Pages: 12