C++ :: Obtaining A Mean / While Sentinel Is 0
Feb 28, 2013
I'm writing a program where a user keeps entering numbers until "0" is entered.Once "0" is entered the loop ends and It displays the mean. Problem is it counts the "0" in the average.
e,g:
Enter number 1: 5
Enter number 2: 2
Enter number 3: 3
Enter number 4: 0
The mean is 2.5. But I want it to only count everything before the "0". (5 + 2 + 3) / 3 = 3.333333
View 3 Replies
ADVERTISEMENT
Sep 11, 2014
I have a couple of issues that i need to fix.This program finds the average of a number desired by the user.For example if they put in 3 and then 1,2,3 then the average is 2.
First of all my program is supposed to stop if zero is inputed. so if i put in 3 as the number of integers that will be averaged, and then i type 1,2,0 it should stop and not calculate the average.
Also, i need to account for negative numbers. so what should i add to accout for negatives?
#include <iostream>
using namespace std;
double avgVal(int, int);
int main() {
int amountOfCases;
cin >> amountOfCases;
int * numbers = new int[amountOfCases];
[Code] ....
View 5 Replies
View Related
Apr 24, 2014
Write a program that will prompt a user to enter a single character, the prompting will continue till a sentinel value is entered. For each character entered perform the following tests and print out a relevant message if the character passes the test. Print out a default message if the character does not pass any of the tests.
Tests that should be in program: Punctuation, Upper Case, Digit, White Space.
Sample Run: “A”, “a”, “7”, <tab>, “?”, “$”
So far I have the following code done. The problem is that when I run the program, the first character is correctly identified. However, every character afterwards is defined as a whitespace character.
#include <iostream>
#include <cctype>
#include <cstring>
using namespace std;
int main() {
char input;
char response;
[Code] .....
View 2 Replies
View Related
Oct 22, 2012
Here is an imgur link to my current homework. [URL] .....
As you can see on there I have them listed on which ones are supposed to be sentinel and which ones are supposed to be count control loops. This is currently what I have:
Code:
#include <iostream>
#include <cmath>
#include <iomanip>
#include <fstream>
using namespace std;
void main() {
int count = 0;
int sum = 0;
[Code] ....
This class has me stumped currently and I am having a hard time breezing through the class at my instructors speed. So I don't want to get too far behind.
Right now this program is giving me an error that opens CMD and gives me infinite lines of "0's".
View 14 Replies
View Related
Aug 24, 2014
My program has a large version of this, where every leaf class is singleton, and pointers of the base class to represent each possible path are stored in a map during compile time. I have it working as follows:
#include <iostream>
#include <string>
#include <map>
[Code].....
But System::initializePrototypes() is constructing the map manually, and I want to use recursion somehow, because my hierarchy is much bigger than this. It's also easy to miss a path doing it the above way, and when new classes are added to the hierarchy, it will be a nightmare to update the map. So the ideal solution is recursion constructing the map perfectly--and when new classes are introduced, nothing needs to be added to System::initializePrototypes().
View 7 Replies
View Related
Nov 5, 2014
I want to generalize my productFunction below to a template family of functions where the template merely changes the * to + or whatever else operator I wish to use.
#include <iostream>
#include <functional>
#define show(variable) std::cout << #variable << " = " << variable << std::endl;
template <typename, typename...> struct ProductFunction;
template <typename RETURN_TYPE, typename FIRST, typename... REST>
struct ProductFunction<RETURN_TYPE, FIRST, REST...> : ProductFunction<RETURN_TYPE, REST...> {
const FIRST function;
using Base = ProductFunction<RETURN_TYPE, REST...>;
[code].....
How can I turn a template parameter into various operators? (apart from using switch statements that will reduce the performance and make the code really ugly) What kind of metatemplating method converts a compile-time constant to an operator?
View 3 Replies
View Related
Aug 28, 2012
I am trying to obtain the values of cookies from a particular website. The problem is, when I run the following code, it only loops through 4 of 10 cookie values present.
Furthermore, the values are turning up as deleted: Reference
HttpWebRequest Request = (HttpWebRequest)WebRequest.Create("http://www.mysite.com");
Request.CookieContainer = new CookieContainer();
HttpWebResponse Response = (HttpWebResponse)Request.GetResponse();
foreach (Cookie cook in Response.Cookies) {
Console.WriteLine("{0} = {1}", cook.Name, cook.Value);
}
Then I came across this code, which states it will loop through every cookie value and obtain its values: Reference
int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;
MyCookieColl = Request.Cookies;
String[] arr1 = MyCookieColl.AllKeys;
for (loop1 = 0; loop1 < arr1.Length; loop1++) {
MyCookie = MyCookieColl[arr1[loop1]];
String[] arr2 = MyCookie.Values.AllKeys;
}
The problem with the above, I can't seem to find a reference to "Request". I am using the libraries "using System.Net and using System.Web", so I am unsure why Request is not being recognized.
My goal is to retrieve one cookie value so that when a user from my website logs in, my C# application will recognize that user.
View 7 Replies
View Related
Jun 13, 2013
I'm looking for a function like GetThreadTimes, but one that gives correct results in a hyperthreading CPU.
For instance, if you start 2 threads on a CPU with 1 physical core and 2 logical cores, GetThreadTimes will say that both these threads use 100% CPU.
However, in reality they only use 50% each. Is there a function that returns correct results, or is there another workaround?
View 8 Replies
View Related