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.
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++)
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.
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[]);
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"
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?
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++)
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.
I'm trying to pass these numbers into the array using the for loop: 1, 2, 3, 4, 5. I created two files in my project called "inStuff.txt" and "OUTPUTS.txt". I know I have an error at my input in the for loop, which is a bit similar to my problem or something? I'm also on linux using a crossGCC complier(not sure if that makes a difference).
#include <iostream> #include <fstream> using namespace std;
im using a for loop to find the index values of the tied high scores and store them into string list then reference list in the second for loop to output it to screen however it isnt letting me use an array with index i as an index its self.
void printHighest(Student s[], int length){ int index; string list[10];//you're never going to have more than 10 people with a tieing highscore. index = findMax(s, length);
[Code] ....
For the time being I simply removed the idea of string list and just put the contents of the second for loop into the if statement above it. However, I am still curious as to if I can reference an index of an array in an index of another array.
I know that returning to main() is not a good idea but how will I loop the program to go back to the position selection when the voter is done voting for the last position.
when I run the program it seems fine. getting the votes from President to PRO Position is fine. The problem is how will the next voter vote without losing the vote (tally) of the previous voter?
FLOW: SELECT POSITION (a-e) ---> SELECT A CANDIDATE (a-c) ---> (this goes on until the position of PRO) ---> ( then go back to the POSITION SELECTION)
After every vote there is a case statement for which I can choose to vote for the next position, quit, or show results (and after showing the results it will go to the next position to vote)....
#include<iostream> #include<string> #include <conio.h> using namespace std; int pca=0,pcb=0,pcc=0,ptv=0;
I am grabbing data from three entities and want to grab a field value in each of the entites and place it in an arraylist. What I would like to do is loop through the arraylist for all the values and do something for each value only once. If the value in the array list is repeated, I want to not do anything for it and continue till the end. Basically, I loop through all the values do something for each value and skip over the repeated value if I already did something.
I have this code that im stuck on what i need to do is Extend the code such that when it starts the user is asked to input values to specify each of the three ranges before moving on to accept and tally the main values how do i do that Using a for loop to input and output array values Also calculate the average
*/ #include <stdio.h> int main(void) { /* Declare an array of integers */ int Grades[5]; int nCount; int nTotal = 0; /* Declare and initialise the value */ float fAverage;
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.
I have a program that makes change from an amount. It works fine, but the output is the correct output looped over and over. I have tried everything, but it still doesn't work. For example, a amount of 98 should print
write a c++ program that reads an unknown number of integer values and then print count, sum and average of odd values, even values, positive values, negative values!!
I've been working on a homework assignment that randomly generates integers and populates them into an array (array1). The program is then supposed to:
1.) copy those values to a second empty array (array2)
2.) sort the values already in array1 (using an inline function)
3.) enqueue the unsorted integers from array2 into a heap vector
4.) a third empty array (array3) is supposed to be populated with those unsorted integers (by dequeuing them from the heap), sorted in reverse order.
But no matter what I do, I always get garbage values like these:
I've tried using both a standard random number generator:
array1[i] = rand()%100+1;
And the d_random.h file my instructor gave us, but nothing works.
Here's the code from all 3 files:
HeapTester.cpp
Code: #include <iostream> // Provides cin, cout #include <cstdlib> // Provides EXIT_SUCCESS, rand, srand #include "d_random.h"//Provides random number generator #include "Heap.h" using namespace std; // Use C++ Standard namespace //Elements in each array. const int arrayLength = 15;//100;
We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.
I was wondering if this was even possible and if so, how do I do it.
else if (speech.ToLower().Contains("truck") && speech.EndsWith(number)) { Here I would like to see if my speech had ended with any of the values i would have stored in the string "numbers". If it did, I would like to just take the value and add it to a new string called whatever }
I have tried this a million different ways and I cant get it to work. I'm not even sure how I would go about storing tons of different numbers in one string, or if that's even possible.
I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.
Here is form1 and form2 code. I have commented out a few things I have tried.
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data;
Goal: Write a program that compares the values stored in the first array to the user inputted values in the second array.
In order to fix this error: [URL]...
I had to change my array initialization to one with a star in front of it:
char a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"}; to: char *a1[]={"a","d","b","b","c","b","a","b","c","d","a","c","d","b","d","c","c","a","d","b"};
I also changed my 2nd array to one with a star in front of it: char *a2[20];
What does this mean exactly? Putting a star in front of an array?
Also, I am now getting an "unhandled exception" when I try to get input for my 2nd array: