•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 426,509 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,161 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 401 | Replies: 11 | Solved
![]() |
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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!
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;
} Last edited by xxjinseruxx : Jul 23rd, 2008 at 11:51 pm.
•
•
Join Date: Aug 2007
Location: South Dakota
Posts: 858
Reputation:
Rep Power: 6
Solved Threads: 86
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
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?
To allow the user to continue entering data sets, enclose the main process in a loop, such as
c++ Syntax (Toggle Plain Text)
char rerun = 'y'; while ( rerun == 'y' ) { //do the work //ask if player wants another go }
What's the purpose of the ratio variable? In your example, how do come up with 12.129?
I think congressmen should wear uniforms like NASCAR drivers so we could identify their corporate sponsors. (unknown)
•
•
Join Date: Jul 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
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
nothing really.
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.
•
•
Join Date: Aug 2007
Location: South Dakota
Posts: 858
Reputation:
Rep Power: 6
Solved Threads: 86
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.
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
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.
Val
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;
}double converter(int x, int y)
{
return (double)x / y; //cast x to type double, get double result
}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
I think congressmen should wear uniforms like NASCAR drivers so we could identify their corporate sponsors. (unknown)
•
•
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation:
Rep Power: 1
Solved Threads: 37
•
•
Join Date: Jan 2008
Location: USA East Cost
Posts: 389
Reputation:
Rep Power: 1
Solved Threads: 37
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";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(); I'm a student. If my statements seem too absolute, feel free to coat them with "In my opinion..." or "I believe...".
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- Google:Supplemental Index Ratio (Search Engine Optimization)
- Ratio in C# HOW?? (C#)
- Memberships / Unique Visitors Ratio??? (Growing an Online Community)
- aspect ratio? (Monitors, Displays and Video Cards)
Other Threads in the C++ Forum
- Previous Thread: Get system() output
- Next Thread: Audio Compression Library in C++


Linear Mode