croconile:
I tryed allready, gives me just more errors (and project type is console =) )
Jeff HS:
here's the code
1 2 3 4 5 6 7 8 9 10 11 12 13 14
Compiling...
stdafx.cpp
Compiling...
FirstCode.cpp
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(7) : error C2447: '{' : missing function header (old-style formal list?)
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(8) : error C2447: '{' : missing function header (old-style formal list?)
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2365: 'exit' : redefinition; previous definition was 'function'
c:\program files\microsoft visual studio 9.0\vc\include\stdlib.h(371) : see declaration of 'exit'
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2440: 'initializing' : cannot convert from 'void (__cdecl *)(int)' to 'int'
There is no context in which this conversion is possible
c:\documents and settings\compaq_omistaja\omat tiedostot\visual studio 2008\projects\firstscript\lässi\firstcode.cpp(27) : error C2447: '{' : missing function header (old-style formal list?)
Build log was saved at "file://c:\Documents and Settings\Compaq_Omistaja\Omat tiedostot\Visual Studio 2008\Projects\firstscript\lässi\Debug\BuildLog.htm"
FirstCode - 5 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Do you have a semicolon after the brackets on main?
1 2
int main(); // the semicolon here will generate error code C2447.
{}
Also, they're right about the .h after iostream. Visual C++ Express 08 considers that an antiquated header. As for the rest of the errors, I can tell you what they mean, but I can't show you where the error is coming from without seeing your code. C2440 indicates that you've attempted an illegal type cast, and C2365 indicates that you've attempted to redifine a class member. If you want more specific information than that, post the code.
Ok, i got the other problems solved, but there's just one thing: this error error C2447: '{' : missing function header (old-style formal list?)
there are two of these errors
The only thing I know of that will cause that error is a loose '{' bracket is just floating around in your code somewhere. That's why a misplaced semi-colon can cause it. Post the offending code and I'll see if I can track down the cause.
//My first code
#include "stdafx.h"
#include <string.h>
#include <iostream>
#include "stdlib.h"
usingnamespace std;
{main () }
{
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
;cout<<"hello"<<endl;
;cout<<"How old are you"<<"?"<<endl;
cin<<a;
;cout<<endl;
;cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
;cout<<"whats your name"<<"?"<<endl;
cin<<b;
;cout<<endl;
;cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
for (int g=10; n>0; n--) {cout<< g << ",";}
;cout<< "Download complete" <<endl;
;cout<< "Guess how many troijans are now in your computer" <<endl;
cin<<c;
;cout<< "wrong" <<m<< "is more correct" <<endl;
;cout<< "have a nice day sucker"<<endl;
;cout<< "Type 0 to exit"<<endl;
cin<<y;
if (y == 0)
{return 0;}
else (y != 0)
{return 0;}
};
int main ()
{
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
;cout<<"hello"<<endl;
;cout<<"How old are you"<<"?"<<endl;
cin<<a;
;cout<<endl;
;cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
;cout<<"whats your name"<<"?"<<endl;
cin<<b;
;cout<<endl;
;cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
for (int g=10; n>0; n--) {cout<< g << ",";}
;cout<< "Download complete" <<endl;
;cout<< "Guess how many troijans are now in your computer" <<endl;
cin<<c;
;cout<< "wrong" <<m<< "is more correct" <<endl;
;cout<< "have a nice day sucker"<<endl;
;cout<< "Type 0 to exit"<<endl;
cin<<y;
if (y == 0)
{return 0;}
else (y != 0)
{return 0;}
}
Insertion operator is the other way around, should be >> not <<
cin>>
Is your stdlib user defined? if not, then you need to use <cstdlib>. I suggest removing all the .h after the library names.
#include <string>
the problem with the .h version is that the compiler may refer the string.h as c-style string library.
Also, you do not declare keywords and function names.
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
the variable m = c * 2; will cause garbage data to be multiplied by 2. You need to initialize c first before using the statement.
And a line does not start with a semicolon. A semicolon is used only at the end of a statement.
here is a fixed version. Make sure to understand what are your errors, it'll help you in the long run when programming in c++
#include "stdafx.h"
#include <string>
#include <iostream>
#include <cstdlib> //I do not see where you used this library.
usingnamespace std;
int main(void) //void is optional, but I am always explicit.
{
int a, b, c, y;
cout<<"hello"<<endl;
cout<<"How old are you"<<"?"<<endl;
cin>>a;
cout<<endl;
cout<<a<<"?"<<" I'm" <<a<<" too!"<<endl;
cout<<"whats your name"<<"?"<<endl;
cin>>b;
cout<<endl;
cout<<"nice to meet you "<<b<<"my name is Johnny"<<endl;
for (int g=10; n>0; n--) {cout<< g << ",";} //This line will execute fast. You need to use a timer to show a count down effect.
cout<< "Download complete" <<endl;
cout<< "Guess how many troijans are now in your computer" <<endl;
cin>>c;
cout<< "wrong" <<(c * 2)<< "is more correct" <<endl;
cout<< "have a nice day sucker"<<endl;
cout<< "Type 0 to exit"<<endl;
cin>>y;
if (y == 0) //regardless of what the user type, the function will still exit.
{return 0;}
else
{return 0;}
}
Ok, ive done some work with the code, but now it error's 101 of these errors:
1 2
error C2784: 'std::basic_ostream<char,_Traits> &std::operator <<(std::basic_ostream<char,_Traits> &,unsigned char)' : could not deduce template argument for'std::basic_ostream<char,_Traits> &' from 'std::istream'
c:\program files\microsoft visual studio 9.0\vc\include\ostream(930) : see declaration of 'std::operator <<'
//My first code
#include "stdafx.h"
#include <string.h>
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int a, b, c, m=c*2, y, cout, cin, endl, if, else, for, main, exit;
std::cout <<"hello"<<endl;
std::cout <<"How old are you"<<"?"<<endl;
std::cin <<a;
std::cout <<endl;
std::cout <<a<<"?"<<" I'm" <<a<<" too!"<<endl;
std::cout <<"whats your name"<<"?"<<endl;
std::cin <<b;
std::cout <<endl;
std::cout <<"nice to meet you "<<b<<"my name is Johnny"<<endl;
for (int g=10; n>0; n--) {cout<< g << ",";}
std::cout << "Download complete" <<endl;
std::cout << "Guess how many troijans are now in your computer" <<endl;
std::cin <<c;
std::cout << "wrong" <<m<< "is more correct" <<endl;
std::cout << "have a nice day sucker"<<endl;
std::cout << "Type 0 to exit"<<endl;
std::cin <<y;
if (y == 0)
{return 0;}
else (y != 0)
{return 0;}
};
//My first code
#include <string.h>
#include <iostream>
#include <cstdlib>
usingnamespace std;
int main ()
{
int a;
int b;
int c;
int m = c*2;
int y;
std::cout <<"hello"<<endl;
std::cout <<"How old are you"<<"?"<<endl;
std::cin >>a;
std::cout <<endl;
std::cout <<a<<"?"<<" I'm" <<a<<" too!"<<endl;
std::cout <<"whats your name"<<"?"<<endl;
std::cin >>b;
std::cout <<endl;
std::cout <<"nice to meet you "<<b<<"my name is Johnny"<<endl;
for (int g=10; g>0; g--) {cout<< g << ",";}
std::cout << "Download complete" <<endl;
std::cout << "Guess how many troijans are now in your computer" <<endl;
std::cin >>c;
std::cout << "wrong" <<m<< "is more correct" <<endl;
std::cout << "have a nice day sucker"<<endl;
std::cout << "Type 0 to exit"<<endl;
std::cin >>y;
}
There's a bunch of typos, and some of the cins don't work, but I'll leave those problems as an exercise to the reader :)
Sorry I took a while in getting back to you. It looks like vince1027 gave you quite a bit of help though. Here's some more:
First of all, since you have the statement 'using namespace std;' at the top of your program, you don't need all the 'std::' before the cin or cout.
In the int declarations, get rid of the 'cout, cin, endl, if, else, for, main, exit;
I'm not really sure what it is you're trying to do, but those aren't valid integer declarations. Also, as vince1027 pointed out to you before, m=c*2 will produce garbage since you haven't initialized int c to any value.
As vince1027 pointed out, the insertion operator following each cin statement should be >>, not <<.
Where you ask for a name, you're attempting to store the name into an int. You won't get the intended results that way. Declare b as a string instead and use that to store the name.
At the end of the program, where you have the if else statement: When you use an else statement the compiler is not expecting another conditional test unless you tell it to. Hence your else, should be 'else if'. Note that this still doesn't do anything, since you have the same results either way.
By the way, interesting choice for a first program. I hope the trojans are a joke, and not something you plan to do with any programming skills you learn...
In the for loop, you've declared int g, and then use n for the rest. It's going to wonder what n is, since you haven't declared it.
[Edit] It looks like I've reiterated a lot of what magicalblender posted while I was typing my response.