C/C++ Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingC/C++ Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old February 17th, 2008, 04:29 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Push in right directions please.

Hello people, im new to C++ and im currently reading a book to help me but unfortunatly i have stumbled at the first hurdle...

Please dont laugh at my following question we all have to start somewhere..

can some please point out where my code is wrong please?
I am using Visual stuido 2005:

//* '01 Main.cpp' *//

//* Input output stream header file *//
#include <iostream>

//* Start *//
main (void)
{
std::cout << "Hello everyone thanks for viewing my first program" << std::endl;
return 0;
}

I get the following error :

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Being new and the book not telling me to expect this im completly stuck... Any help will be appriacted thanks in advance..

Reply With Quote
  #2  
Old February 17th, 2008, 04:52 PM
UsefulIdiot UsefulIdiot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 11 UsefulIdiot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 29 sec
Reputation Power: 0
small addition

I tried your program and it was actually working, bu the only thing was there was no pause so it would immediately exit from the screen before you could read anything. Here, i added a pause function and it works fine.
//* '01 Main.cpp' *//

//* Input output stream header file *//
#include <iostream>
#define frz system("pause");
//* Start *//
int main()
{
std::cout << "Hello everyone thanks for viewing my first program" << std::endl;
frz;
return 0;
}


Quote:
Originally Posted by Nedge
Hello people, im new to C++ and im currently reading a book to help me but unfortunatly i have stumbled at the first hurdle...

Please dont laugh at my following question we all have to start somewhere..

can some please point out where my code is wrong please?
I am using Visual stuido 2005:

//* '01 Main.cpp' *//

//* Input output stream header file *//
#include <iostream>

//* Start *//
main (void)
{
std::cout << "Hello everyone thanks for viewing my first program" << std::endl;
return 0;
}

I get the following error :

error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

Being new and the book not telling me to expect this im completly stuck... Any help will be appriacted thanks in advance..

Reply With Quote
  #3  
Old February 17th, 2008, 05:20 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by UsefulIdiot
I tried your program and it was actually working, bu the only thing was there was no pause so it would immediately exit from the screen before you could read anything. Here, i added a pause function and it works fine.
//* '01 Main.cpp' *//

//* Input output stream header file *//
#include <iostream>
#define frz system("pause");
//* Start *//
int main()
{
std::cout << "Hello everyone thanks for viewing my first program" << std::endl;
frz;
return 0;
}


Thank you very much i noticed the problem as your code worked i missed the int, before the Main..

Thanks again im sure u will hear from me again haha.

Reply With Quote
  #4  
Old February 18th, 2008, 11:15 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Learning variables

ok second problem is...

im allowing the user to input information but at the moment i cant seem to get it to allow more than one Character, yet i can get it to allow more than one number...

any help will be appricated thanks in advance

/* 01 Main.cpp */
#include <iostream>

int main (void)
{
/*Variable declaration*/
char Name;
short Age;
char Sex;
/* get the information */
std::cout <<"What is your name?: ";
std::cin >> Name;
std::cout <<"How old are you?: ";
std::cin >> Age;
std::cout <<"What are you male or female?: ";
std::cin >> Sex;
/*showing the information*/
std::cout << "Hello " << Name << " welcome to my second program."<< std::endl;
std::cout << "Wow your " << Age << " years old, thats amazing."<< std::endl;
std::cout << "It is great to hear that you are " << Sex << " that is wicked."<< std::endl;
return 0;
}

Reply With Quote
  #5  
Old February 18th, 2008, 02:11 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Instead of char use a std::string. You'll have to #include <string>

The char datatype is just that, one character. And you are not really getting 'more than one number', you are getting one number which happens to consist of multiple digits

Good luck
__________________
There is no such thing as C/C++, you either program C or C++

Reply With Quote
  #6  
Old February 18th, 2008, 07:33 PM
UsefulIdiot UsefulIdiot is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 11 UsefulIdiot User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 28 m 29 sec
Reputation Power: 0
second problem

char declaration is for only one character, you need to use a string instead. Ex: string name. that will accept input up to the first space.

Quote:
Originally Posted by Nedge
ok second problem is...

im allowing the user to input information but at the moment i cant seem to get it to allow more than one Character, yet i can get it to allow more than one number...

any help will be appricated thanks in advance

/* 01 Main.cpp */
#include <iostream>

int main (void)
{
/*Variable declaration*/
char Name;
short Age;
char Sex;
/* get the information */
std::cout <<"What is your name?: ";
std::cin >> Name;
std::cout <<"How old are you?: ";
std::cin >> Age;
std::cout <<"What are you male or female?: ";
std::cin >> Sex;
/*showing the information*/
std::cout << "Hello " << Name << " welcome to my second program."<< std::endl;
std::cout << "Wow your " << Age << " years old, thats amazing."<< std::endl;
std::cout << "It is great to hear that you are " << Sex << " that is wicked."<< std::endl;
return 0;
}

Reply With Quote
  #7  
Old February 19th, 2008, 09:54 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
Quote:
Originally Posted by UsefulIdiot
char declaration is for only one character, you need to use a string instead. Ex: string name. that will accept input up to the first space.


Slight correction:

If you use
string s;
cin >> s;
That will move one word into s.

You can also use
getline(cin,s);
to get a whole line.

Reply With Quote
  #8  
Old February 19th, 2008, 02:39 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by MaHuJa
Slight correction:

If you use
string s;
cin >> s;
That will move one word into s.

You can also use
getline(cin,s);
to get a whole line.


Right so what do I do?

Im confused where do i put this code to help it work. I just dont complie now i got confused

Can u place in into my code for me please, Sorry to be a pain, but im still learning, and this will hel.

Thanks in advance.

Reply With Quote
  #9  
Old February 20th, 2008, 04:39 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
cpp Code:
Original - cpp Code
  1. /* 01 Main.cpp */
  2. #include <iostream>
  3. using std::cout;    // Note the 'missing' std:: in the code below
  4. using std::cin;
  5. using std::getline;
  6. using std::endl;
  7. #include <string>
  8. using std::string;
  9.  
  10. //using namespace std;  // can replace all the using lines above
  11.  
  12. int main (void)
  13. {
  14.     /*Variable declaration*/
  15.     string Name;
  16.     short Age;
  17.     char Sex;
  18.     /* get the information */
  19.     cout <<"What is your name?: ";
  20.     //cin >> Name;  // Would take a single word
  21.     getline(cin,Name);
  22.     cout <<"How old are you?: ";
  23.     cin >> Age;
  24.     cout <<"What are you male or female?: ";
  25.     cin >> Sex;
  26.     /*showing the information*/
  27.     cout << "Hello " << Name << " welcome to my second program."<< endl;
  28.     cout << "Wow you're " << Age << " years old, thats amazing."<< endl;
  29.     cout << "It is great to hear that you are " << Sex << " that is wicked."<< endl;
  30.     return 0;
  31. }

Reply With Quote
  #10  
Old February 20th, 2008, 12:53 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Problem Solved Thanks People i'l be back with next problem soon haha. had to removed Std::Getline ... it was causing an error...

Reply With Quote
  #11  
Old February 21st, 2008, 02:00 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Edited and re-posted below.

as i had changed the code

Reply With Quote
  #12  
Old February 21st, 2008, 02:44 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
I do not have access to the msvc compiler atm so I do not know what c1010 is and it would be easier if you posted the line number of the error as well

But from what I can see you misspelled square. The forward declaration and the definition both are spelled sqaure but the function called is spelled corrrectly square

Reply With Quote
  #13  
Old February 21st, 2008, 02:47 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Ok new Problem...

Error..
fatal error C1010: : unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

on this code, anyone spot it?

/* '02 Main.cpp' */

/* input output stream header */
#include <iostream>

double Cube (double Value);

int Main (void)
{
double Number, CubeNumber;

std::cout << "Enter a number: ";
std::cin >> Number;

/* Number is the function argument */
CubeNumber = Cube (Number);

std::cout << CubeNumber << std::endl;

return 0;
}

/* Value is the function parameter */
double Cube (double Value)
{
double CubeReturn;

CubeReturn = Value * Value * Value;

return CubeReturn;
}


P.s Icon ive edit the spellig mistake and slighty changed since your post but here it is again.

Reply With Quote
  #14  
Old February 21st, 2008, 03:34 PM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Quote:
Originally Posted by Nedge
Error..
fatal error C1010: : unexpected end of file while looking for precompiled header. Did you forget to add '#include "stdafx.h"' to your source?

Well, at the risk of stating the obvious, have you tried the obvious? Have you tried adding #include "stdafx.h" to your file? If you do not want to (need to) include that you can turn off use of precompiled headers somewhere in the project options (probably under the c/c++ header).

Reply With Quote
  #15  
Old February 22nd, 2008, 03:55 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by Icon
Well, at the risk of stating the obvious, have you tried the obvious? Have you tried adding #include "stdafx.h" to your file? If you do not want to (need to) include that you can turn off use of precompiled headers somewhere in the project options (probably under the c/c++ header).


ok i re-wrote the program and strangly i get a new error now..

1>MSVCRTD.lib(crtexe.obj) : error LNK2019: unresolved external symbol _main referenced in function ___tmainCRTStartup
1>C:\Users\Nedge\Documents\Visual Studio 2005\Projects\03 Square Rooting\Debug\03 Square Rooting.exe : fatal error LNK1120: 1 unresolved externals

Reply With Quote
  #16  
Old February 22nd, 2008, 04:04 PM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 336 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 15 h 51 m 40 sec
Reputation Power: 12
Send a message via AIM to Bobidybob
2 things:

first, make sure it is the very first line in your code. it must be before everything else.

second, if that doesnt work, then turn off precompiled headers.

Project-> (project name) Properties... -> C/C++ -> Pre-compiled Headers

change to Not Using Precompiled Headers under the create/use precompiled headers section. this all assumes you're using something similar to VS2005. I think VS2008 is the same.
__________________

Reply With Quote
  #17  
Old February 22nd, 2008, 04:12 PM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by Bobidybob
2 things:

first, make sure it is the very first line in your code. it must be before everything else.

second, if that doesnt work, then turn off precompiled headers.

Project-> (project name) Properties... -> C/C++ -> Pre-compiled Headers

change to Not Using Precompiled Headers under the create/use precompiled headers section. this all assumes you're using something similar to VS2005. I think VS2008 is the same.


ok i re-wrote the program and its sorted, i has used a templeted page by mastake... and this was where my problem was...

Thanks for your help.

Reply With Quote
  #18  
Old February 22nd, 2008, 04:15 PM
Bobidybob's Avatar
Bobidybob Bobidybob is offline
Contributing Abuser
Click here for more information
 
Join Date: Apr 2007
Location: Starkville, MS
Posts: 336 Bobidybob User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 Days 15 h 51 m 40 sec
Reputation Power: 12
Send a message via AIM to Bobidybob
also, don't capitalize main()

Note: its kinda funny the randomness of the order of the posts

Last edited by Bobidybob : February 22nd, 2008 at 04:17 PM.

Reply With Quote
  #19  
Old February 23rd, 2008, 05:29 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Ok i had this code working, before i added srand (time (NULL))

Can anyone see why its not working now i added thats code I get a error saying

error C3861: 'time': identifier not found

Here is my code.

/* "01 Main.cpp" */

/* input output stream header */
#include <iostream>
/* Standard library header */
#include <stdlib.h>

int main ()
{
short Number;
short Guess = 0;

/* Get random number and one to prevent it from bein zero */
srand (time (NULL));
Number = rand () %100;
Number++;

/* Until player finds the number continue to loop */
while (Guess !=Number)
{
std::cout << "Enter a Number between 1 and 100: ";
std::cin >> Guess;

/* If guess is higher give hint */
if (Guess < Number)
{
std::cout << "You are guessing to low.";
std::cout << std::endl;
}
/* If guess is lower, give hint */
if (Guess > Number)
{
std::cout << "You are guessing to high.";
std::cout << std::endl;
}
}
/* show win message */
std::cout << "Congratulations you got it!." << Number;
std::cout << std::endl;

return 0;
}

Reply With Quote
  #20  
Old February 23rd, 2008, 06:37 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
"Identifier not found" means it doesn't recognize the name. In this case, it's because you haven't done the #include that lets it know there is a function called time() in the libraries.

To find the name of the file you have to include: (From most to least preferred)
-Read the documentation
-Search the include directories
-Guess


Oh and also...
"Enter a Number between 1 and 100: "
Really means 2-99 inclusive.
(From-to)

Reply With Quote
  #21  
Old February 23rd, 2008, 11:04 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by MaHuJa
"Identifier not found" means it doesn't recognize the name. In this case, it's because you haven't done the #include that lets it know there is a function called time() in the libraries.

To find the name of the file you have to include: (From most to least preferred)
-Read the documentation
-Search the include directories
-Guess


Oh and also...
"Enter a Number between 1 and 100: "
Really means 2-99 inclusive.
(From-to)


Thanks I was missing #include <time.h> haha how simple is tht haha...

Reply With Quote
  #22  
Old February 24th, 2008, 03:45 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
First game code.

Ok ive just coded my first small game, and from what i can tell im good as there.. There is over 200 lines of code so i will try not to post it, and i started with 30 errors and have reduced it to 2 error and 7 warning...

i was hoping for a little advice on the warnings..

Compiling...
main.cpp
error C2447: '{' : missing function header (old-style formal list?) I cant see where im missing a {....
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data Never has this before.. i dont understand this
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
warning C4244: '=' : conversion from 'double' to 'unsigned long', possible loss of data
warning C4244: '=' : conversion from 'double' to 'unsigned long', possible loss of data
error C2065: 'default' : undeclared identifier Im not sure whats wrong with this?
warning C4244: 'return' : conversion from 'unsigned long'


I understand this code aint much use without the code but there is about 200 lines.. and maybe someone will be able to suggest what to look for..

Thanks in advance

Reply With Quote
  #23  
Old February 24th, 2008, 04:10 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Well, I think that it is not a '{' you are missing, the '{' is just the point where the compiler thinks it should get something else, in this case a missing function header. I am not sure how much help this is without seeing the code.. Check if your function has declared a return type and see if the parameters are correct.

Reply With Quote
  #24  
Old February 24th, 2008, 05:46 AM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
error C2447: '{' : missing function header (old-style formal list?)
Incorrect:
int main {
Correct:
int main() {

warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
A time_t is, in your implementation, a 64-bit type. When converted to an unsigned int, which is 32-bit, some information may get lost. (These numbers, particularly the size of time_t, can be different from compiler to compiler.)
There are two solutions:
-use time_t for the value you're storing it in (preferred)
-explicitly state that you want the conversion to occur. I would guess one of your lines would be
srand(static_cast<unsigned int>(time()));

C++ style casts (explicit conversions) are somewhat 'ugly', but they're supposed to be.
"An ugly operation should have an ugly syntactic form."
Read Stroustrup's page for more information. (Stroustrup created C++)

warning C4244: '=' : conversion from 'double' to 'unsigned long', possible loss of data
Same deal. A double can have a number larger than a unsigned long int can hold, and it will also lose all information "less than one".
It's pretty much the same deal as above; but worse.
There are perhaps some functions you call that return a double, where you're trying to store the return value in an int.

error C2065: 'default' : undeclared identifier
I would guess a more informative message would in your case have been:
Syntax error: Missing ':' after default

That's the probable thing anyway - in a switch statement, each case n and the default must all have a : after them, marking them as labels. (You can 'goto' to labels manually, but don't. Just don't.)

Reply With Quote
  #25  
Old February 24th, 2008, 08:21 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
This is the begining section to my code where it claims the error is. can anyone spot it?



/* 01 main.cpp */

#include <iostream>
#include <stdlib.h>
#include <time.h>

void ShowIntroScreen (void);
void ShowInformation (unsigned long Money);
short GetBet (void);
short DoDiceThrow (void);
unsigned short DoMoneycalc (short Dice, short Bet, short BetMoney);
unsigned long GetAmount (void);

int main (void);
{
unsigned long MoneyEarned;
unsigned long Money;

short DiceValue;
short Bet;
short BetMoney;
/* show intro and setup game */
ShowIntroScreen ();
Money = 1000;

/* Play while player has money
Keep 100 Pound for cab home */
do
{
ShowInformation (Money);
/* Get Bet information */
Bet = GetBet ();
BetMoney = GetAmount ();
DiceValue = DoDiceThrow ();
MoneyEarned = DoMoneyCalc (DiceValue, Bet, MoneyBet);

Money -= BetMoney;

/* Show the Number */
if (MoneyEarned == 0)
{
std::cout << "You Lost. Number was: " << DiceValue;
std::cout << std::endl << std::endl;
}
else
{
std::cout << "You Won " << MoneyEarned - BetMoney;
std::cout << "Pounds. Number was: " << DiceValue;
std::cout << std::endl << std::endl;

Money += MoneyEarned;
}
}

Reply With Quote
  #26  
Old February 24th, 2008, 08:26 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
int main (void);

remove the trailing semi-colon

Reply With Quote
  #27  
Old February 24th, 2008, 09:26 AM
Nedge Nedge is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Feb 2008
Posts: 14 Nedge User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 h 42 m 44 sec
Reputation Power: 0
Quote:
Originally Posted by Icon
int main (void);

remove the trailing semi-colon


did this and now i get this (more errors)

1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(33) : warning C4244: '=' : conversion from 'unsigned long' to 'short', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(35) : error C2065: 'MoneyBet' : undeclared identifier
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(35) : error C3861: 'DoMoneyCalc': identifier not found
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(121) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(127) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(134) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(140) : warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(147) : error C2365: 'DoMoneyCalc' : redefinition; previous definition was 'formerly unknown identifier'
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(156) : warning C4244: '=' : conversion from 'double' to 'unsigned long', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(163) : warning C4244: '=' : conversion from 'double' to 'unsigned long', possible loss of data
1>c:\users\nedge\documents\visual studio 2005\projects\01 game craps\01 game craps\main.cpp(179) : warning C4244: 'return' : conversion from 'unsigned long' to 'unsigned short', possible loss of data
1>Build log was saved at "file://c:\Users\Nedge\Documents\Visual Studio 2005\Projects\01 Game Craps\01 Game Craps\Debug\BuildLog.htm"
1>01 Game Craps - 3 error(s), 8 warning(s)



Worked, i noticed 2 spelling mistakes i still got 8 warnings but no errors

Thanks

Reply With Quote
  #28  
Old February 24th, 2008, 09:39 AM
Icon's Avatar
Icon Icon is offline
Command Line Warrior
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Sep 2005
Posts: 1,021 Icon User rank is Private First Class (20 - 50 Reputation Level)Icon User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Weeks 8 h 12 m 36 sec
Reputation Power: 15
Great I think MaHuJa explained those conversion warnings already.

Reply With Quote
  #29  
Old February 24th, 2008, 06:15 PM
MaHuJa's Avatar
MaHuJa MaHuJa is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Dec 2007
Posts: 1,177 MaHuJa User rank is Private First Class (20 - 50 Reputation Level)MaHuJa User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Week 1 Day 21 h 27 m 36 sec
Reputation Power: 13
Send a message via Skype to MaHuJa Send a message via XFire to MaHuJa
*****

Last edited by MaHuJa : February 24th, 2008 at 06:16 PM. Reason: Redundant

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingC/C++ Help > Push in right directions please.


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap