C++ :: If And Else Statements With Game Scores

Oct 20, 2014

I am in comp. Sci 1 at my school and I have to write a program that deals with gamer scores and the trophy they get according to expert level. For example Tom is a beginner and gets a gold medal if >=10000 a silver >= 7500 bronze if >= 5000 and no trophy if he score <5000 ! I have do this scoring for Beginner, Immediate and Expert.

Should I set up the beginning like this:

case'b':
case 'B':
if (score >= 10000 )
trophy= gold
if (score >= 7500)
trophy = silver
if (score >= 5000)
trophy= bronze
else = none

Not really sure how to go about solving this problem

View 4 Replies


ADVERTISEMENT

C++ :: Save Top 10 Scores In Simon Game - Filling Array Not Working Correctly

May 17, 2013

I wrote a Simon game, and wanted to save the top 10 scores. I was working right, until I decided I wanted to still be able to read the file if someone enters a name containing spaces. Now, the results aren't right.

void FillScoreList(string Simon_Names[], int Simon_Scores[]) {
ifstream Simon_HiScores("Simon_Data.txt");

if (Simon_HiScores.is_open()) {
for( int x=0;x<10;x++){

[Code] ....

Even without trying to read names with spaces, I'm getting

dad 1
0
340176
0
... either a long number or a zero. No names

View 4 Replies View Related

C++ :: Read Scores From File And Displays All The Scores

Aug 19, 2014

Okay so suppose that a text file grade.txt contains an unspecified number of scores. How would I program that reads the scores from the file and displays all the scores, their total and average? Scores are stored in the format of one score per line. Im having trouble with the whole #include <fstream> file and how to lay it all out in visual studio.

View 1 Replies View Related

C++ :: Game Design Practice For Accessing Container Of Game Objects

Dec 21, 2014

I'm working on my first video game. So far I have a few classes in the game starting with the Game class which includes a list of GameObjects (another class). There are several classes that inherit from GameObjects used to implement things like bullets, explosions, various enemy types, etc.

The game essentially iterates through the list of GameObjects to update/render them. I would like to provide access to the Game's list of GameObjects inside another class (like the Bullet class) so I can put new objects on the list. For example, when a bullet hits, I want to add an explosion to the Game's GameObject list it can be updated/rendered.

How this should be setup? I was considering adding a pointer to the Game or GameObject list to the GameObject class (and methods to access it), but I was wondering if there is a better way to set this up?

View 4 Replies View Related

C++ :: Program For Calculating Total Price Of Game Station And Game

Sep 13, 2014

I would like to make a program for calculating the total price of a game station, and a game. I made a program like this for just the price of a game in class, but I want to make one that does the game system as well.

View 7 Replies View Related

C/C++ :: If Else Statements Being Ignored

Feb 7, 2015

My problem is that some of my conditions are not being triggered when the price level of a medium or large discount is smaller than the cost of the widget(defined as .40) An example being ,base price, $2 med discount 80%, and large discount 90%. My med discount is,1.6(80%) off of 2, so $.40, which is fine, but 90% off mean 1.8(90%) off of a base of $2, which is $.20 which is too low., and should trigger the 4th if statement, Nick you are discounting large purchases too much!. However when I run this in the program, I am triggering the first if statement.

#include <math.h>
#include <stdio.h>
#define widget_cost 0.40
int main (){
float sellprice;
float discount_med_price;

[Code] ....

View 2 Replies View Related

C :: Use Recursion To Permutate Scores

Feb 8, 2013

I have this problem set that has to use recursion to permutate scores. I have read in all the numbers and have tested that it works . l have also attached what I have so far. Here is what I think I need to do:I have to pass the structs into this permutation algorithm that is here:

Code:
#include <stdio.h>
void ListPermutations(char str[]);
void RecursivePermute(char str[], int k);
void ExchangeCharacters(char str[], int i, int j);

[Code]....

View 1 Replies View Related

C++ :: Display Scores On Notepad

Mar 16, 2014

I have a problem on my program. I want to display the scores on notepad. I can display it but the problem is every time I play the game the previous score got erased and replaced by the new one.Here's my code.

cout<<" Enter your name: ";
cin>>a;
cout<<endl<<endl;
cout<<" Your name is "<<a<<" and your score is "<<right<<endl<<endl;
ofstream MyFile ("score.txt");
MyFile << a <<" "<<right;
MyFile.close ();

View 4 Replies View Related

C++ :: Getting Test Scores Using Pointers

Jan 12, 2014

I'm trying to basically have a user input the amount of test they want averaged, then have the user input the test scores. Send the test scores to a function and have them ordered in ascending then send it to another function that averages it. When I wrote the function I keep getting the address back instead of the actual values.

#include <iostream>
#include <iomanip>
using namespace std;
void arrSelectSort( int* [], int);
void arrAverage(int);

[Code] .....

View 3 Replies View Related

C++ :: How To Calculate Number Of Scores Above 90

Apr 7, 2013

I have a program that allows the user to enter a specific number of test scores. Based on these test scores, the program should display the average score and calculate how many of the scores were above 90. I have most of it done but I'm having trouble figuring out how to calculate the number of scores that were above 90. What am I doing wrong?

This is my code:

#include <iostream>
#include <iomanip>
using namespace std;
// Function prototypes
double average(double*, int);
int howManyA(double*, int);

[Code]...

View 1 Replies View Related

C++ :: How To Store Test Scores

Jan 25, 2015

i have so far, and im having trouble finding a way to store 5 test scores for each student that has been entered. for example: enter name: chaotic enter id number: 12312312

Enter test score 1:
Enter test score 2:
Enter test score 3 etc.......

heres me code so far

#include <iostream>
#include <string>
#include <iomanip>
#include <cstdlib>
using namespace std;

[Code]....

View 1 Replies View Related

C :: Boolean Value Use For If And Else Statements

Apr 20, 2013

Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements.

Code:
#include <stdio.h>
#include <math.h>
#define GRAVITY 9.8
#define LIMIT 500
#define SEC 5

[Code] ....

View 2 Replies View Related

C :: IF Statements Within Loops

Jan 29, 2014

I've just started learning the C language, and I'm stuck on something that is probably quite simple.how to get IF statements working within WHILE loops. My code is below. I am trying to write a program to count the number of words in a sentence, and obviously stop counting after a full stop has been entered. I created a variable called 'spaces' which will increase by one after the user enters a space. However, when the IF statement is in place, the loop never terminates, even if I enter a full stop. When I delete the IF statement, the loop functions correctly.

Code:

#include <stdio.h>
int main()
{
char x;
char a;
char y;
int spaces = 0;
}

[code]....

View 4 Replies View Related

C++ :: How To Use If Statements With Strings

Jul 3, 2013

I've got a very simple but annoying problem.

if (letter3=="
"){
letter3==letter;
PrintCharacterLineEnd();

This is a code. the string "letter3" contains the string "
". What I want to happen is when, letter3 contains the text "
" I want to go to the function PrintCharacterLineEnd.

However, as of right now it's not working.

View 14 Replies View Related

C/C++ :: Using Strings And If Statements?

May 3, 2012

The problem with this code is that there are no errors showing, but when i compile the program, the if else statements do not carry out as they should do. Both if statements show the same answer, for example the second if statement. If I type Y or N then I get the same thing, 'You will now choose an event'. How do i get rid of this problem? Is char supposed to be used or string?

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

[Code].....

View 1 Replies View Related

C/C++ :: Program That Scores Blackjack Hand?

Jun 5, 2014

Write a program that scores a blackjack hand. In blackjack, a player receives from two to five cards. The cards 2 through 10 are scored as 2 through 10 points each. The face cards - jack, queen, and king are scored as 10 points. The goal is to come as close to a score of 21 as possible without going over 21. Hence, any score over 21 is called "busted". The ace can count as either 1 or 11, whichever is better for the user. For example, and ace and a 10 can be scored as either 11 or 21. Since 21 is a better score, this hand is scored as 21. An ace and two 8s can be scored as either 17 or 27. Since 27 is a "busted" score, this hand is scored as 17.

The user is asked how many cards she or he has, and the user responds with one of the integers 2,3,4, or 5. The user is then asked for the card values. Card values are 2 through 10, jack, queen, king, and ace. A good way to hande input is to use the type char so that the card input 2, for example, is read as the character '2', rather than as the number 2. Input the values 2 through 9 as the characters '2' through '9'. Input the values 10, jack, queen, king, and ace as the characters 't', 'j', 'q', 'k', and 'a'. (Of course, the user does not type in the single quotes.) Be sure to allow upper - as well as lowercase letters as input.

After reading in the values, the program should convert them from character values to numeric card scores, taking special care for aces. The output is either a number between 2 and 21 (inclusive) or the word Busted. Use fucntions, multiway branches, switch statements or nested if-else statements. Your program should include a loop that lets the user repeat the calculation until they are done doing so.

The code runs properly for the first card but then it asks if the user wishes to repest the program. I need to claculate the value of all cards before it asks for that. Here is my code:

#include <iostream>
using namespace std;
int main()
{

[Code].....

View 5 Replies View Related

C/C++ :: Function To Read Scores Into Array?

Apr 16, 2015

I am currently in a beginner C programming class. I have written most of my code and the problem that I am running into when i compile and run the code. I am able to input more than required scores for input. I think my code is wrong from line 126-136. The program runs fine with no errors. I'm just unable to input the required number of scores allowed.

/*************************************************************************
* A program to calculate grade.
*************************************************************************/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

[Code].....

View 2 Replies View Related

C/C++ :: Average Scores For Diving Competition

Aug 27, 2014

float total, avg, max, min;
float judge[4];
int index;
int array[2];
int main() {
total = 0.0;

[Code] ....

At a diving competition, the mark given to each diver is awarded as follows:

There are a number of judges and each judge gives a mark and the final mark is found by leaving out the highest mark and the lowest mark and calculating the average of the rest.

Write a C program that reads in the number of judges at the competition and then reads in a mark for each judge. Perform the necessary calculations and display the highest mark, the lowest mark and the final mark.

The following data checks must be carried out in the program:

a)the number of judges must be from 4 to 8

/>each judge can give a mark from 0.0 to 10.0 (a real number that may include fractions)

If an invalid amount is entered, the program must ask for an acceptable value to be entered instead.

Note: this program does not need an array. However, you can use an array if you want to.

View 6 Replies View Related

C :: For Loop Skipping Statements

Jan 26, 2013

im a newbie C user and im having a little trouble in these for loop of mine im using. the first iteration is all fine but on the second and succesive iterations the first gets statement is skipped. im making a program that would ask the user to input multiple informations for atleast 5 people. i was also asked to use structures.. here is the code i have come up so far.. ive been stuck in it for like 3 hours now.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}

[code]....

gets part for the line "Enter ID Number is skipped on the second iteration..

View 3 Replies View Related

C :: If Statements For Dice Rolling

Oct 9, 2014

I'm very new to C Programming and am doing some homework for my intro to C class. "There is a game where one can play and bet money on. Two dice are rolled and the numbers that appear on the dice are added together. If the total is 7 or 11, then the user wins. If the total is 2 or 12, then the user loses. If a different total appears. then the user gets their money back."

I have written the program below:

Code:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
int d1,d2,sum;
d1=0;
d2=0;
}

[code]...

However, after finishing the program, I realized that I NEEDED to use random numbers!!! How do I make my program generate random numbers within a range of 1-12? Also, how do I make my program generate NEW random numbers EVERY TIME instead of ONCE??

View 1 Replies View Related

C :: Statements Within Braces Are Indented

Apr 25, 2013

When we say that the statements within the braces are indented, we mean a tab character distance? For example if we have :

Code:

// K&R Style
void some_function(void)
{
<1 tab>int x=1;
<1 tab>printf("Inside the function");
while(x<3) {
<1tab><1tab>printf("Inside the loop");
x++;
}
return;
}

That is right?

View 3 Replies View Related

C :: Operators In Switch Statements?

May 20, 2013

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char).

So does that mean switch statements can only test if variable == value and nothing more, like > < >= <= != etc... ? I tried to make a program to test this and it seems like switch statements are limited to == but I'm not sure, maybe I'm doing something wrong.

This is the program I tried to make to test this:

Code:
#include <stdio.h>
int main () {
int n;

[Code]....

So is it true that switch statements only work with the built in == operator? if that was the case then I would feel rather meh about switch statements.

View 7 Replies View Related

C++ :: Switch Statements In GLUT

Jan 3, 2014

I'm making a game in OpenGL GLUT. A ball is going to move forwards along the Z axis and hit a wall. I want to be able to move the ball left and right, up and down before firing it off on the Z axis. I'm using glutSpecialKeys for this, and I've got everything set up, but I'm not sure how I use it with a switch statement? Here is a snippet of code:

void Special_Keys (int key, int x, int y){
switch(key){
case GLUT_KEY_UP: //do something
break;
case GLUT_KEY_DOWN: //do something

[Code] .....

Where the comment is saying "do something", I'm not sure what I actually need to do? Is it a method or what?

View 1 Replies View Related

C++ :: Randomizing Order Of If-else Statements

Dec 11, 2013

The purpose of doing this is so that the top of the if statements is not preferred over the bottom. I tried assigning enum values to each case. Then choose a random integer r from 0 to the size of the std::list myList containing those enum elements. The enum value is found using it = std::next (myList, r). Then if the if statement corresponding to that enum value is false, then myList.erase (it), and repeat the process with the newly reduce myList. It works, and everything seems nicely randomized. But it is disappointing much slower than when I used the original if-else statements (it is being applied hundreds of times).

Here is a snippet of my code (I decided not to use switch statements because it looked too clumsy):

std::list<FacingDirection> guyFacingDirections = {Positive_x, Negative_x, Positive_y, Negative_y, Positive_xPositive_y, Positive_xNegative_y, Negative_xPositive_y, Negative_xNegative_y};
while (true) {
const int r = rand() % guyFacingDirections.size();

[Code] .....

There is a crowd of girls. Each guy will choose a girl, and then choose a facing direction to dance with his chosen girl. But not all facing directions are possible if someone is standing at the spot he wants to stand at to get his desired facing direction. Without randomizing the if-else statements, most of the guys will end up facing the same direction, which I don't like.

View 18 Replies View Related

C++ :: How To Combine Inputs Using If Statements

Jul 19, 2013

How to combine the if statements?

cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}

[Code]...

View 13 Replies View Related

C++ :: String Inputs On If Statements

May 26, 2014

How to make an input with a string thats part of an if statement. How I think it should be done :

#include <iostream>
#include <string>
using namespace std;
int main() {
string choose;

[Code] .....

But I get a strange warning (not an error, but something that is like "just letting you know" i suppose) and when i enter in ss or SS or aa or AA, it breaks my app.

View 7 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved