Hey, basically im trying to create a Kill/Death ratio program where the user types x number of kills and y number of deaths and this creates an answer for ratio " :1" for example " how many kills ? 3388 " "How many deaths? 1237" "Your ratio is 12.129:1" the decimal is needed if possible oh and just one more i need the program to loop [hence the end code, not that it works]

so heres the code im using up to now. and if you need it explaining any more or dont understand please tell me!

// ArenaRatio.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include "Converter.h"

using namespace std;

 int x;
 int y;


int main ()

 

{


float x,y, dummy;



float ratio = .046;
//declare variables
	char rerun;

cout<<"Welcome to Easy ArenaRatio finder!\n";

cout<<"\n";

cout<<"\n";

cout<<"\t Please enter the numbers of kills: \n" << endl;
cin >> x;
cout<<"\t Please enter the numbers of deaths: \n" << endl;
cin >> y;

 



cout<<"Your Ratio is: "<< converter(x, y) / ratio << ":1" << endl;



system("PAUSE");

//prompt user if they wish to run the program again
cout << "Would you like to input information for another ratio? <y/n>: ";
cin >> rerun;





return 0;
}

Ohh man, you need to properly indentent your code. It so difficult to go through with that code.

Identent your code, you might except more help.

And what is '#' char in each line? Dosnt look good!

ssharish

First, what's with all the extraneous "#' symbols? They're only needed for the include statements.

To allow the user to continue entering data sets, enclose the main process in a loop, such as

char rerun = 'y';
while ( rerun == 'y' )
{
   //do the work
   
   //ask if player wants another go
}

As to your calculation, where's the converter( ) function? What does it do?
What's the purpose of the ratio variable? In your example, how do come up with 12.129?

Indentent? O_O?

Edit : Removed not needed "#"

Ok Vmanes, the loop works perfect thanks on that one, and to answer the part about "12.219:1" was just and example and doesnt really mean anything i was just explaining what i need the end result to show after you enter how many kills and deaths you have divided by the ratio the exact ratio is 2.74:1 rounded up but when i do the ratios i end up with wrong numbers example

i input 3388 in kills and 1272 in deaths the answer should be about 2.68:1 but if i do it right now with the code i get "1.#INF:1" [ratio set at = 0.000] all i need it to do is divide like a calculator does but with only 0.00 digits or rounded up to the nearest hundreth and not the long amount of digits a calculator shows and stick ":1" at the end of it. and as for the converter

#include "stdafx.h"
#include <iostream>

int converter(int x, int y)
{
	return x / y;
}

nothing really.

You've got two parts to getting the result you want.
First, get the correct numeric value. Your function, as shown above, will not give you the correct result.

int converter(int x, int y)
{
	return x / y;
}

dividing an int by an int results in an int, which is also the type of your return value. You will lose the fractional part of the division's result. This should be

double converter(int x, int y)
{
	return (double)x / y; //cast x to type double, get double result
}

Forget that ratio variable, it's not needed. Especially if you set it to 0.00 !!!

To get a value displayed just to the hundredths, you need to use output formatting.

cout.setf(ios::fixed | ios::showpoint);
cout.precision(2);
cout<<"Your Ratio is: "<< converter(x, y)  << ":1" << endl;

Val

commented: Great advice =) +2
commented: Good post. +5

oh wow!, thanks the new edited code works....you helped alot Vmanes your awsome :icon_cheesygrin:

You might want to also add a check in converter() (or somewhere else) to make sure that the number of deaths is not 0.

Right, how do i do that? oh and one more thing.. when it reruns..it does it underneath the old text..is there anyway to make it rerun as though its been opened fresh? thanks alot!

int converter(int x, int y)
{
    if(y == 0)
        return 0;//or -1, or whatever you want to happen instead of a divide by zero	
    return x / y;
}

You could use backspace to get rid of the old text:

for(int i = 0;i < numChars;i++)
    cout << "\b";

numChars is the number of characters you output.

There's a clear command on the Linux kernel that clears the prompt of text. I don't know if there's a Windows equivalent, but you could call it with system();

thanks alot you helped, i added this code

if(y == 0)
        return 0;

to my Double Converter and it shows 0.00:1 if the deaths are 0.. thanks alot now only thing i need is, a peice of code that Erases the last peices of information..and reruns the program [it reruns perfectley now but starts again under the last peice of information from the last Ratio, if anyone has a way to do this i'll close this topic as solved thanks!

yea thanks alot for that Cool Gamer, it was

System ("cls");

Topic Solved

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.