Jump to content


Photo

Needed help with something


  • Please log in to reply
9 replies to this topic

#1 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 21 December 2003 - 10:07 PM

The main problem is that the comments are backwards. You need to use // not \\
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#2 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 22 December 2003 - 03:50 PM

For me, getch doesn't work correctly. The program doesn't display the output first, it just exits when I hit enter again, and I don't see the output.
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#3 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 22 December 2003 - 07:12 PM

'void main' :(


#pragma hdrstop
#include <iostream.h>
#include <conio.h>

int main()
{

double HoursPerDay;
double MoneyPerDay;
double Answer;

cout << "How many hours do you work per day?";
cin >> HoursPerDay;
cout << "How many money do you make for the hours?";
cin >> MoneyPerDay;

Answer = HoursPerDay * MoneyPerDay;

    if(HoursPerDay > 24)
      cout << "You Must Be Jocking!!!";
    else
      cout << "You make" << Answer << "Money per day";

  getch();

}


Using void is like saying "please shutdown" to XP when it's running on a 486DX2.

#4 Mad Ivan

Mad Ivan
  • Project Team
  • 115 posts
  • Location:Bug City
  • Projects:Allies Revenge 3

Posted 22 December 2003 - 09:54 PM

ok, i repaired it but still the same.

#pragma hdrstop
#include <iostream.h>
#include <conio.h>

int main()
{

 double HoursPerDay;
 double MoneyPerDay;
 double Answer;
/// double blah;

 cout << "How many hours do you work per day?";
 cin >> HoursPerDay; 

   if(HoursPerDay > 24)
    cout << "You Must Be Jocking!!!";
   else
    cout << "How many money do you make for the hours?";
    cin >> MoneyPerDay;

 Answer = HoursPerDay * MoneyPerDay;

   cout << "You make" << ' ' << Answer << ' ' << "$ per day";
   cout <<"\n";

  getch();

}

Posted Image

#5 Detail

Detail

    King Detail

  • Hosted
  • 7,767 posts
  • Location:Dayonic
  • Projects:Dayvi.com
  •  Blu Spy

Posted 22 December 2003 - 10:10 PM

My code works fine for me.
What error does Dev-C++ say?

#6 Eradicator

Eradicator
  • Members
  • 220 posts
  • Location:Canada

Posted 22 December 2003 - 10:52 PM

Mad Ivan you'll have to tell us whats wrong if you want us to help. We can't guess :p Is it compiling? Is it giving wrong output? What?

#7 Mad Ivan

Mad Ivan
  • Project Team
  • 115 posts
  • Location:Bug City
  • Projects:Allies Revenge 3

Posted 23 December 2003 - 08:52 AM

lol.srry.

No errors.
When i compile my program and run it, everything is fine.It works ok, but at the end it simply exits.No matter do i put getch() or void main() with return 0 - it will close after i have entered the second number.

I have attached the program.See that it exitst.

Attached Files

  • Attached File  Cpp1.exe   200.08KB   70 downloads

Posted Image

#8 vice

vice
  • New Members
  • 6 posts

Posted 24 December 2003 - 01:00 AM

well, seeing as you've forgotten to put braces around the else code

 if(HoursPerDay > 24)
   cout << "You Must Be Jocking!!!";
  else
 {
   cout << "How many money do you make for the hours?";
   cin >> MoneyPerDay;
 }

im not sure as to what options dev c++ uses when it runs the command prompt, wether to keep it open after program is done executing. however, int main() and return 0; should work.

#9 Mastermind

Mastermind

    Server Technician

  • Undead
  • 7,014 posts
  • Location:Cambridge, MA
  • Projects:MasterNews 3
  •  The Man Behind the Curtain

Posted 24 December 2003 - 04:31 AM

Yeah, it works fine for me with VC 6.0 at school. It displays the press any key to continue. There might be a problem with the input stream not getting flushed correctly.
:p
Posted Image

Well, when it comes to writing an expository essay about counter-insurgent tactics, I'm of the old school. First you tell them how you're going to kill them. Then you kill them. Then you tell them how you just killed them.

Too cute! | Server Status: If you can read this, it's up |

#10 Eradicator

Eradicator
  • Members
  • 220 posts
  • Location:Canada

Posted 25 December 2003 - 08:24 AM

No matter do i put getch() or void main() with return 0

Don't use void main() and return 0. That defeats the purpose of using void. I'm not really sure if I can do a good job of explaining why theres different words there to a beginner but i'll give it a shot.

int is short for integer as you probably know by now. When you declare int main() you are declaring the main function (you can call other functions, but main is the function that will automatically run). The int part comes because you can make a function output a variable. So I could have double main() or whatever. But in most cases you don't really want or need main to output something so in C you can use void main(). Which basically says its a void or null value as in there is not and will never be any data outputted from that function. So therefore it does not make sense to return 0 to a void function because you are not returning anything. return basically says what value to give the function if it can output a value. I hope that is accurate as I'm a bit rusty with c++.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users