473,385 Members | 1,934 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Need help with a c++ program quitting

So, I wrote this program for a friend. However, after the first variable input by the user, which is the variable "MONSTER", the program unexpectedly quits. Any help would be appreciated. I am using the DMC compiler.

Expand|Select|Wrap|Line Numbers
  1. #include <iostream.h>
  2.  
  3.  
  4.  
  5. //Calculates average percentage of item dropping//
  6.  
  7. char MONSTER;
  8. char ITEMDROP;
  9. char DROPRATE;
  10. char DROPAMOUNT;
  11. char MONNUM;
  12.  
  13.  
  14. int main()
  15. {
  16.     cout << "Welcome to Pantherias's Runescape Drop Percentage Calculator.";
  17.     cout << "This tool will determine how often a item drops after you input"; 
  18.     cout << "the neccessary data.";
  19.     cout << "Please enter the monster name, then press ENTER.";
  20.     cin >> MONSTER;
  21.     cout << "Now please type the name of the item being dropped,";
  22.     cout << "then press ENTER.";
  23.     cin >> ITEMDROP;
  24.     cout << "After you are satisfied with the fighting,";
  25.     cout << "type the number of the monster you killed,";
  26.     cout << "then press ENTER.";
  27.     cin >> MONNUM;
  28.     cout << "You are fighting" << MONNUM << " of " << MONSTER << " and attempting to recieve " << ITEMDROP << ".";
  29.     cout << "Please fight 100 of these monsters, then type in the amount of the item you get";
  30.     cout << "followed by ENTER.";
  31.     cin >> DROPAMOUNT;
  32.  
  33.     DROPRATE= (DROPAMOUNT*100/MONNUM);
  34.  
  35. cout << "The " << MONSTER << " dropped  " << ITEMDROP << " approximately " << DROPRATE << " percent of the time over " << MONNUM << " kills.";
  36. return 0;
  37. }
  38.  
  39.  
  40.  
  41.  
Nov 1 '08 #1
3 1395
AmeL
15
Well, I find nothing wrong with your code beside the incompatibility of the data type u declared and the inputted data.
Example :
MONSTER : should be declare as an array of char not char.
So please reconsider this case again.
NOTE : One more thing, I would like to say that even your data type should be integer, yet you have to declare it as an array of char to prevent any unexpected error occurred when user input the char type instead of number type.

Thanks
/AmeL
Nov 1 '08 #2
archonmagnus
113 100+
There are a few things wrong with your code. First, I suggest replacing the depreciated library file "iostream.h" with the more compatible (and useful) "iostream". In other words, first change your first line to read:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
Next, by declaring a variable such as you've done with
Expand|Select|Wrap|Line Numbers
  1. char MONSTER;
  2.  
you've created a box named "MONSTER" that holds one (and only one) value. In the case of your code, that value will only be the first letter of what ever you've input. For example, if you have the following code:
Expand|Select|Wrap|Line Numbers
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main (void)
  6. {
  7.     char monster;
  8.  
  9.     cout<<"Monster name: ";
  10.     cin>>monster;
  11.  
  12.     cout<<endl
  13.         <<"You entered: "<<monster<<endl;
  14.  
  15.     return 0;
  16. }
  17.  
you could expect to see the following output:
Expand|Select|Wrap|Line Numbers
  1. Monster name: Bruxa
  2. You entered: B
  3.  
  4.  
I'm sure this isn't what you really want. If I may, I'd suggest reading on the use of C++ strings to store the entirety of the input (including any whitespace that be in a monster's name such as the string "Dire Wolf").

Here's a reference to the C++ string library. You might particularly be interested in the use of getline().
Nov 1 '08 #3
Alright guys, I'll see what I can do. Thanks for the help, though! This is the first c++ program I've written in a long time, so I'm kind of rusty...but I'm getting back into the hang of it.
Nov 1 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

32
by: Dave Benjamin | last post by:
Hey all, I just realized you can very easily implement a sequence grouping function using Python 2.3's fancy slicing support: def group(values, size): return map(None, * for i in...
0
by: Deaconess | last post by:
I am quitting this group - ever since I joined I have been at least 15 Microsoft viruses a day if not more. Good luck to you all. Back to Yahoo
1
by: David Arden Stevensonn | last post by:
My goal is to load an xml document from a remote url, make some changes to it, and then display it in a webpage. Say my codebehind looks like this private void Page_Load(Object sender, EventArgs...
6
by: Peter Kleiweg | last post by:
I have an application written in Tkinter. There is a menu item 'quit' that calls the function 'quit'. If 'quit' is called, it first checks if there is unsaved data. If there is, it won't let the...
4
by: Jim Seymour | last post by:
Hi, Environment: SunOS 5.7 Generic_106541-29 sun4u sparc SUNW,UltraSPARC-IIi-Engine Postgresql-7.4.6 Build config: --with-java --enable-thread-safety gcc version 3.3.1 less-381 readline-4.3
0
by: Loney | last post by:
Take a look at the script below: 'we send 7 parameters server, db, channel, reportbase, start_debug, account, refreshtime WScript.Sleep 10000 refreshtime=refreshtimeseconds...
5
by: smileskhan | last post by:
Hay Friends... Here I started a new and interested thread. I hope you also enjoy it. I got a task to creat a Hospital Database in Java. But I donīt have any good clues abouts it....
3
by: =?iso-8859-9?B?RGlu52F5IEFr5/ZyZW4=?= | last post by:
When I execute the following code #include <stdio.h> #include <stdlib.h> int main(void) { FILE *bmp; bmp = fopen("deneme.bmp","w"); fputc(10,bmp);
4
by: powerovergames | last post by:
I wrote a simple gambling game using java, and I wish to let the user to save their record(i.e # of rounds played, points gained per round) so after quitting they game, they could keep on playing...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.