C++ :: Initializing Loop And Returning Values Rock Paper Scissors

Dec 2, 2013

When i return 0; at the function int userselect (int user, int comp)my output displays twice and when i ask the user to run it again the computers selection of rock, paper or scissors remains the same it doesn't find a new random number. So i made the function userselect return to main(). This works and my output is displayed once, but when i run it it skips my while part of my do while loop completely so it loops the program without asking the user if they wish to run it again.

but when i return main() the computers choice re-randomizes every time so i need to find a way to get the while part of my do while to initialize and the program to not loop without the option of ending it.

#include <iostream>
#include <string>
#include <cmath>

[Code]....

View 1 Replies


ADVERTISEMENT

C :: Rock Paper Scissors Program?

Oct 10, 2013

what im trying to do is an option to play again. if the user decides to play again then i want the options to execute again and if the user choses not to play again then i want the game to show the scores.

here is what i have so far:

Code:

// Purpose: Play the Rock-Paper-Scissors-Lizard-Spock Game
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

[Code]....

View 10 Replies View Related

C/C++ :: Rock Paper Scissors Console Game

May 14, 2014

I made a rock paper scissors game in c++. How to make it better, and what i can do differently

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

int checkConvertInput(string signs[], int wins, int draws, int losses);
void calculateWinner(int playerSign, string signs[], int &wins, int &draws, int &losses);
void endResult(int wins, int draws, int losses);

[Code] .....

View 1 Replies View Related

C++ :: Rock Paper Scissors Game - How To Add Play Again Option

Apr 1, 2014

So , i had to make an rock paper scissors game . After lot of hard work and struggle ,I completed it but my professor rejected it since I didnot add option where it says "Would you like to play again .Y/N " . The code has too many brackets ! Here is my code

#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;

// for displaying the outputs to the user; passing string to functions
void user_win() {

[Code] ....

View 1 Replies View Related

C/C++ :: Rock Paper Scissors - Displaying Output And Choosing Random Option?

Aug 11, 2014

today I've been working on a rock, paper and scissors game. It compiles OK, except:

It doesn't use a random number from 1 -3, or goes out of scope.2. It doesn't COUT and it doesn't flush the buffer.3.

My code is as follows:

#include <windows.h>
#include <iostream>
#include <cstdlib>
#include <ctime>
std::string randomPC(int &);
void PCSelect(int &);

[code]....

View 2 Replies View Related

C :: Returning Values From While Loop

Jul 13, 2013

I am currently doing a bodyfat calculator for a course in school.I'm having a problem getting an output returned from my while loop, which determines the user's gender by user input.My function (outside of main) is currently:

Code:

char gendercheck(gender){
while (true) {
gender = _getch();
if (gender == 'M' || gender == 'm') {
system("cls");
printf("Your selected gender is male.");
break ;

[code]....

My failed tries include "return gender" and "return genderpicked" statements in both the if-functions and the loop itself, which I have deleted since that didn't work. My goal is to get a character stored in gender, so that I can use the information of the user's gender in my main function from this point and onwards.

MY MAIN IS:

Code:

int main() {
char *genderpicked ;
char gender ;
genderpicked = &gender ;

[code]....

View 9 Replies View Related

C++ :: Initializing Pointers To Memory Addresses Or Values?

Aug 31, 2014

What is the difference between initializing pointers to a memory address using the address operator like int *pointer = &x; or initializing it to a value like int *pointer = x; .. in other words how does p and q point to the same memory address in:

const int ARRAY_LEN = 100;
int arr [ ARRAY_LEN ];
int *p = arr;
int *q = &arr[0];

View 4 Replies View Related

C++ :: Returning Values To Main

Nov 5, 2014

I am working on this program below. The problem I am having is trying to return totalDays to the main. In the numOfDays() function there is a for loop that adds the totalDays (totalDays = totalDays + days). I have just been getting errors in returning the correct amount of totalDays to the main from the numOfDays function.

#include <iostream>
using namespace std;
int numOfEmployees();
int numOfDays(int);
int main() {
int totalDays = 0;

[Code] ....

View 2 Replies View Related

C++ :: Returning Multiple Values?

Oct 9, 2013

I would like to return multiple values from one function to access in different functions. For example:

int function1(//what goes here?)
{
int a ;
a = 1 + 2 ;
int b ;
b = 3 + 4 ;

return (what goes here if i want to return the value of a and/or b to use in another function?) ;

void function2()
{
//now i want to use the value of a here to use in an equation, how do i do that?
//now i want to use the value of b here to use in an equation, how do i do that?
}

View 4 Replies View Related

C++ :: Functions Returning Values?

Apr 9, 2014

I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:

#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;

[Code]....

View 19 Replies View Related

C++ :: Write A Function Returning 2 Values?

Jul 23, 2013

So I have a function like the one below

bool get_array( float input_param, vector<int>& output_param ){
// some code that handles output_param output
if( error ) return false;
}

So basiclly this function must return 2 value well one of the value is just a bool returning whether the procedure doesn't fail at some point or not.

is there any better way to write this function ?

View 7 Replies View Related

C :: Array Function Not Returning Correct Values

Apr 1, 2013

I have been trying to make a function that compares all the values of the array and if they are all equal will return a value to print true. The problem I am having is that regardless of what values I enter the function is always returning true. Any way to tell the program o check all the values in one command instead I put them each,

Code:
#include<stdio.h>
#include<stdlib.h>

int compare(int arrayA[], int arrayB[]);

[Code]....

View 2 Replies View Related

C/C++ :: Function Not Returning Values - Structs In Arrays

Feb 25, 2015

I wrote this code for a homework assignment, everything runs fine but the function void percent_votes (line 66) isn't calculating properly, it outputs 0.00 for each value. I have tried everything I can think of to try and make it work.

Here is the assignment: Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.

Here is the code I have written:

#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>

[Code].....

View 4 Replies View Related

C/C++ :: Switch Case Statement Not Returning Correct Values

Mar 21, 2015

My code is supposed to read a five to four digit code of a resistor from a file and determine the resistor's nominal, lower and upper tolerance values. I have inputted my file's first resistor code as a string so I could run tests on it but the problem that occurs is that a get the wrong values from my switch-case statements. I have put printfs after the function call to see what the values were and they turned out wrong. If I could get my return values to be right then I could be on my way coding.

#include<stdlib.h>
#include<stdio.h>
double bandNum(char x); // function prototype that will read the resistor value for the first, second and possibly third band
double bandMult(char x); // function prototype that multiplies the resistor by some value of 10
double bandTol(char x); // function prototype that the tolerance of the resistor is multiplied by

[Code] ....

View 5 Replies View Related

C++ :: Returning Values Or Using Pointers To Redefine Variables Passed As Arguments?

Feb 28, 2014

Which is more efficient in functions? Returning values or using pointers to redefine variables passed as arguments?

I mean either using:

void ptr_Func(int *x)
{
*x = *x+1
}

or

int ptr_Func(int x)
{
return x + 1;
}

In terms of speed, memory use etc.I want to know general efficiency, I know it will obviously vary with different uses and circumstances.

View 7 Replies View Related

Visual C++ :: GetMost And GetLeast Functions Returning Erroneous Values

Apr 5, 2014

After compiling, I cannot understand why my getMost and getLeast functions are returning erroneous values. I've done everything I could think of to try and fix this, Problem and code below.

A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a twodimensional 3 * 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should rst have the user input the data for each monkey. Then it should create a report that includes the following information:

* Average amount of food eaten per day by the whole family of monkeys.
* The least amount of food eaten during the week by any one monkey.
* The greatest amount of food eaten during the week by any one monkey.

Input Validation: Do not accept negative numbers for pounds of food eaten.

Code:
#include <iostream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;

// Constants.
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;

[Code] ....

View 3 Replies View Related

C/C++ :: Circle Paper Of Radius R - Max Cone Volume

Jan 23, 2014

My problem is the following : We have a circle paper of radius R. We will cut off a sector of this circle (with length rem_sec), and the remaining (bigger part) will create a cone. Radius of cone base is r.

I need to create a code that prompts the user to enter circle's radius R and the program will calculate the length of removed sector (rem_sec) so that the created cone has the Max Volume.

I wrote the following code, but it doesn't work. It displays both rem_sec and MaxV = 0.

#include <iostream>
#include <cmath>
#include <iomanip>
#include <conio.h>
using namespace std;
const double PI = 3.1415;
int main() {
double rem_sec;

[Code] ...

View 5 Replies View Related

C Sharp :: Setting Custom Paper Size Of Crystal Report?

Sep 20, 2014

I want to print a report half sheet in A4 size..

I tried to change paper size in coding and in properties also but no use..so what is the correct code to change as custom size of report.

View 1 Replies View Related

C++ :: How To Add Values Of For Loop

Feb 9, 2014

I want to add each of the values that are calculated by the end of each for loop.

For example:

for(int i = 0; i < 10; i++)
{
int x;
}

I want to be able to add all of the x values calculated from the for loop together. How to do that?

View 6 Replies View Related

C++ :: How To Total The Values That Are Put In During The Loop

Oct 23, 2014

How to total the values that are put in during the loop. For this program I need to add up the values the user inputs and then display them after the loop. Here is what I have:

#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
int main() {
const int firstQuiz = 1, lastQuiz = 4;
int quiz, quizGrade;
for (quiz = firstQuiz; quiz <= lastQuiz; quiz++)

[code]...

View 4 Replies View Related

C++ :: Function Returns Values After Loop Done

May 15, 2013

I am writing a program with a function that includes a long loop. I need this function to return a value when each loop is done, to send this value to output, in order to follow the progression. But I don't know how to do it in easy way. The function is like follow:

int goC(){
... // some local value definition
for(int i = 0; i < 1000; i++){
... // a lot of calculations done here
return i; // -> return the value after each loop is done
}
}

Here it only returns one value, i = 0. Clearly it's wrong.

View 10 Replies View Related

C/C++ :: Loop Not Comparing Values Correctly?

May 12, 2014

So, I have the beginnings of a rock paper scissors game which i have created before in Java, and i am attempting to create it in c++.

Problem is, the function "int checkConvertInput" containing a loop to make sure input is valid, is not exiting the loop. As far as i can see the two strings are not comparing. Is there a library function for this? I know C had strcmp but i am not sure if it applies here.

#include <iostream>
#include <string>
#include <vector>
using namespace std;
int checkConvertInput(int playerSign, string signs[]);

[Code] ....

View 6 Replies View Related

C/C++ :: Storing Values In Arrays Using For Loop

Nov 18, 2013

I am trying to create a program that will give me an value for a chosen from the user array ut I believe the program I've made does not recognize the values of the previous arrays. (Here is my program):

#include<stdio.h>
int main() {
int n;
int i;
int j;
float c;
float a[10000];

[Code] ....

There must be problem cause every value I give n(only for n=1 the answer is correct) the result is "a[n] is -inf"

View 1 Replies View Related

C++ :: Adding Up Values Of Dice Rolls In A While Loop

Feb 19, 2013

I'm having a problem adding up the values of the dice rolls in a while loop. The program will only store the last value so how would I get it to store multiples values? Here is my program thus far. I would try an array but we haven't gotten to that yet.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main() {
int die_1=0, die_2=0, total_score1, total_score2, player1score;
char enter;

[Code] ....

What operators or equation I should use to accomplish this?

View 7 Replies View Related

C++ :: Using For Loop To Input And Output Array Values

Jan 23, 2014

so i got this piece of code today having some slight errors with it, how its actually done as i want to know where i have gone wrong here is the code .. Using a for loop to input and output array values

*/
#include <stdio.h>
int main(void) {
/* Declare an array of integers */
int Grades[5];
int nCount;
/* Populate the array */
for(nCount = 0; nCount < 5; nCount++)

[Code]...

View 3 Replies View Related

C/C++ :: Finding Sum Of Values Entered By User In While-loop?

Aug 26, 2014

Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values,and the sum of values. Note that to keep the sum, you have to decide on a unit to use for that sum; use cm.

View 9 Replies View Related







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