C/C++ :: Calculate Percentage Of Even Numbers Entered By User In Array

Nov 18, 2014

exercise in c: write a program which calculates % of even numbers entered by a user in an array;

1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.

int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);

[Code] ....

View 1 Replies


ADVERTISEMENT

C/C++ :: Calculate Result Of 2 Numbers That User Entered

Oct 29, 2012

In this exercise, write a rational number calculator that ask the user to enter two rational number:

a/b + c/d

and produce the result:

(ad+bc)/bd

View 10 Replies View Related

C :: Calculate Black Body Spectra Over User-entered Range Of Wavelength And Temperatures

Jul 29, 2013

I tried to write a code to calculate black body spectra over an user-entered range of wavelength and temperatures. The equation I'm trying to code is the second one this image (stolen from Wikipedia)The syntax to run it is bbgrid lambda_inic lambda_final temp_inic temp_final inc_T inc_lambda

where bbgrid is the name of the program, lambda_inic and lambda_final are the limits of the wavelenght range (in units of angstroms, 1A=10⁻⁰m), temp_inic and temp_final are the limits of the temperature range (in Kelvins) and inc_T and inc_lambda are the increments. What I want to do is, given the ranges of temperatures and wavelengths, to run the code over the lambdas and the temperatures.

The problem is that the behaviour of the intensities (what I'm calculating) is erratic. Sometimes it is highly positive, sometimes immensely negative and turning between those two. As an example of an output file, I'm getting things like this:

3100 1915076038
3110 -1233496775
3120 1741010116
3130 1229780625
3140 421722788
3150 -1874760945
3160 1654746252
3170 1062468321
3180 -795217626
3190 -1141129750
3200 -1570716956
3210 539385985

While I was trying to debug the code, I found the problem may reside in the exponential factor in the denominator. I wrote some lines to calculate and print on the screen only the exponential, and it was oscillating like crazy. The output file should produce curves like this:

Code:

#include<stdlib.h>
#include<stdio.h>
#include<math.h>
#include<string.h>

[code]....

View 14 Replies View Related

C :: Calculate Number Of Distinct Values Entered Into Array

Sep 12, 2013

I'm trying to calculate the number of distinct values entered into an array. If i enter the followings "3,4,5,6,7,7,6,e (anything that's not a number)" . I get a total of 7 but in reality it should be a 5.

Code:

#include <stdio.h>
//---------function to find the distinct values----
int find_distinct(int list[], int size)
{
int i, j,size2, distinct = 0;
for(i = 0; i < size; i++)

[Code]...

View 9 Replies View Related

C :: Write A Code To Find All The Prime Numbers Before A User Entered Number

Apr 9, 2014

I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.

Code:

#include <stdio.h>
int is_prime( int num );
int get_positive_integer(void);
int main( ) {
int upper; /* upper limit to check */
int num; /* current number to check */
int isprime;
/* used to flag if number is prime or not */

[Code]...

It says the error is on line 23

View 6 Replies View Related

C++ :: Looping And Calculate The Percentage?

Mar 7, 2013

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

[Code].....

I AM HAVING TROUBLE CALCULATING THE PERCENTAGE. I HAVE TO CALCULATE THE AMOUNT OF MONEY FOR 6 YEARS.

View 1 Replies View Related

C/C++ :: Calculate Cost From Wholesale To Final With Percentage Markup

Apr 15, 2014

Program calculates cost from wholesale to final cost with percentage markup!

#include <iostream>
using namespace std;
int calculate_retial(int,int);
int main () {
int wholesale;
int markup;
int cost;

[Code] ....

View 5 Replies View Related

C/C++ :: Create Program To Calculate A Percentage For Commission And Bonus?

Feb 11, 2014

I am using codeblocks for school and I am trying to create a program to calculate a percentage for commission and a bonus. I have tried using a decimal for percentage, int and floats with casting. Every time it I try it displays 0 or just the bonus. I even took and did a test page. My head is about to pop.

Write an algorithm that can be used to calculate the commission earned in a real estate transaction. The chart below describes the formulas used to calculate the commission.

Sales Price Commission
Less than $100,000 5% of Sales Price
$100,000 to $300,000 $5,000 + 10% of Sales Price over $100,000
More than $300,000 $25,000 + 15% of Sales Price over $300,000

// Commission and Bonuses.
#include <iostream>
#include <iomanip>

[Code].....

View 2 Replies View Related

C++ :: Program To Calculate Total Grade For N Classroom Exercises As Percentage

Mar 5, 2013

Write a program that calculates the total grade for N classroom exercises as a percentage. The user to input the value for N followed by each of the N scores and totals. Calculate the overall percentage (sum of the total points earned divided by the total point possible) and output it as a percentage. Sample input and output it as a percentage. Sample input and output is shown below.

How many exercises to input?
score1: 10
total points possible: 10
score2: 7
total points possible: 12
score3: 5
total points possible: 8

Code:
# include <iostream>
using namespace std;
int main () {
double N=0, score, total, totalScore=0, totalGrade=0, GRADE;
cout<<"How many excersices will be scored?/n";

[Code] .....

Error:
1>------ Build started: Project: HOMEWORK5, Configuration: Debug Win32 ------
1>LINK : error LNK2001: unresolved external symbol _mainCRTStartup
1>C:UsersWORKHOMEWORK5DebugHOMEWO… : fatal error LNK1120: 1 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

View 4 Replies View Related

C++ :: Calculate Percentage Of Times Coin Flipped Either Heads Versus Tails

Feb 10, 2015

I'm having trouble getting the program to calculate the percentage of times it flipped either heads versus tails. I realize what I currently have doesn't work because above I initialized heads and tails by giving them values of 0, but I'm unsure of how to fix it.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;
int main () {
srand(time(0));

[Code] .....

View 2 Replies View Related

C++ :: Dice (with Varying Number Of Sides) Program To Calculate Percentage Of Results

Oct 28, 2013

I am trying to code and compile a program that requests a uses to first inpu the number of sides they wish for a dice to have and secondly input the number of dice throws they would like to calculate the value for. The program will print an error message and default the number of sides the dice has to 5 if the number entered is below 4. Finally it will print out a percentage figure for each value that results from all the the dice rolls.

I have attached my header, driver and class files below along with accompanying error messages below them

// file name Exercise.cpp
#include <iostream>
#include "Die.h"
using namespace std;
int main() // the main program begins here
{
char restart = 'y'; // declare variables
double numRolls = 0.0;
int diceTot = 0;

[Code] .....

View 5 Replies View Related

C++ :: How To Store Class Info Entered By User Into Array

May 7, 2013

So I have an array of my own class, "Restaurant," but I'm having a hard time figuring out how to store the info entered by the user into the array.

In total, I have two classes. I will show you all I have, it's a lot but I know it will be easier to understand.

My problem is in the AddRestaurant(), since that is where I should ask the user for all the information and store it in the array.

Also consider that I have to use the FTime class as well to handle the time. Basically I want to do something like this:

info[count].SetRating();

which will put the rating part of the class Restaurant into the array[count]

Also, my program doesn't compile because of the AddRestaurant and PrintAll functions since what I am showing is what I want to do, not what works.

//main.cpp
#include <iostream>
#include <iomanip>
#include <string>
#include "Restaurant.h"
#include "FTime.h"
int ReadMenuChoice();

[Code] .....

View 4 Replies View Related

C++ :: Find Unequal Elements In Array Entered By User

Jan 12, 2014

I would like to know the algorithm or flow for finding unequal elements in an array entered by user. I tried using for loop but didn't get the expected output

Code:
#include <iostream>
#include <string>
using namespace std;
int main() {
int a[10],b[10]; //array of integer elements

[Code] ....

View 6 Replies View Related

C++ :: If Statement Error - Match Text Variable That User Has Entered With Another Got From Array

Dec 3, 2014

I have an if statement that should either match a text variable that the user has entered and a another text variable that has been got from an array but they won't match even if they are the same,Im at a lost with it.

void displayQuestion(int noQuestion, string questionArray[], string answerarray[], string answer, double scorearray, double finalscore){

cout << questionArray[noQuestion] << endl;
cout << "enter an answer " << endl;
cin >> answer;

[Code] ....

View 1 Replies View Related

C++ :: User Input - Calculate Sum Of Only Positive Values While Ignoring Negative Numbers

Jun 19, 2014

So I have to make a program that allows the user to enter both positive and negative numbers and the program is suppose to calculate the sum of only the positive values while ignoring the negative values. Also it is to be a sentinel-controlled loop with a number ending the set of values.

View 4 Replies View Related

C++ :: User Input Two Numbers - Calculate Square Root Then Roots Are Added Up To Return Sum

Aug 23, 2014

I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.

#include<iostream>
#include<cmath>
float main(){
using namespace std;
float m1,m2,m3,m4,m5;

[Code] ....

View 4 Replies View Related

C :: User Inputted Validated Grade As Percentage

Jan 2, 2014

I am trying to get this program to accept two inputs Student number and grade and validate them both

However the program skips over the student number

Code attached AssignmentProgram.c

View 1 Replies View Related

C/C++ :: Find Max Number Entered By User And Terminate When Negative Number Entered

Jul 15, 2014

I am trying to find the max number entered by the user, and it should terminate when a negative number is entered. For my code, it will just end when the user inputs a lower number than the previous. i.e.- 10 20 15 "The highest number is 20" when it should be "10 20 5 40 15 -1" "The highest number is 40". No arrays or do/while loops either.

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

[Code] ....

View 9 Replies View Related

C++ :: Calculate Average From File Containing Array Of Numbers?

Feb 21, 2014

I have written two separate programs; Program 1 calculates the average of an array of numbers which has been hard-coded into the program. Program 2 reads an array of numbers from a text file and displays them on the output.

I wish to combine these two programs into one by making Program 1 read the array of numbers from the file and then calculate the average using that instead of the array { 84, 92, 76, 81, 56 } as outlined below. I only wish to display the average in the output, not the number array as Program 2 does.

I have tried to do most of the work, I just need modifying the code slightly so it reads the number array from the file and calculates the average.

Program 1

#include <iostream>
#include <cmath>
#include <math.h>
#include <fstream>
#include <string>
#include <numeric>
using namespace std;
int main() {
const int nNumStudents = 5;

[Code] .....

View 7 Replies View Related

C++ :: Store User Input In Array And Calculate Mean / Median And Mode - Bubble Sorting

Mar 26, 2014

I'm trying to make a c++ program of this but i don't know how to use the bubble sorting.

Write a C++ application that asks the user to enter 10 numbers. The program then stores those numbers in an Array. The program should display the Mean , Median, and Mode.

Mean is the average of the 10 numbers.
Median is the average of the 5th and the 6th numbers. (But you have to arrange the numbers in ascending order first using Bubble Sort before calculating the Median.)
Mode is the most frequent number among the 10 numbers.

View 5 Replies View Related

C++ :: How Many Entries Entered By The User

Sep 16, 2014

when i declare local variable x and use it in array,the error is occure that use of un assign local variable.

namespace ConsoleApplication11
{class Program
{
static void Main(string[] args)
{
int x;
Console.Write("enter how many entries you want");

[Code]...

View 2 Replies View Related

C :: Checking What User Has Entered (City)

Mar 9, 2013

I am using Dev C++ on a windows computer.

In my code, the user enters the name of a city, and then according to what city it is, the program displays the coordinates of that city

I can't find a way of figuring out and checking which city the user has entered so the code can displays its appropriate latitude and longitude.

View 9 Replies View Related

C++ :: How To Use A User Entered File In Fstream

Feb 14, 2014

So, I am making a name-database-type-thing and I want the user to be able to enter there own file. Like, here:

string fileName;
string name;
cout<<"What is your file name?"<<endl;
getline(cin, fileName);
ifstream nameFile(fileName);
getline(cin, name);
nameFile<<"Name: "<<endl;

Well, that last part is in a loop, so you can enter an unlimited number of names to the .txt file.

So, it won't let me use the string in ifstream. How can I fix this? This maybe unclear, so if it is just say so and I will edit it.

View 6 Replies View Related

C++ :: How To Collect Input That Has Been Entered By User

Mar 19, 2013

I am making a program that will suggest meal options when choosing specifics contained within, e.g. style, base, main, sauce.

What I would like to know is how to collect the input that has been entered by the user, say you are given 4 lists and each has an option, how could I chain these together in order to cout a suggestion that is in my database?

-------------------------------------------------------------------------------
Example (not my real Q's and A's):

OUTPUT: What meat would you like?
INPUT: "Beef" //<collect this!
OUTPUT: What sauce would you like?
INPUT: "Tomato" //<and this!
OUTPUT: What would you like to have as the main/base?
INPUT: "Pasta" //<and this!
OUTPUT: I can suggest... "Spaghetti Bolognese" //< and return this from the database using the 3 filters
--------------------------------------------------------------------------------

View 1 Replies View Related

C++ :: Echo String Entered By User

Oct 3, 2013

/*
* echoString2.c
* Echoes a string entered by user. Converts input to C-style string.
*/

#include <stdio.h>
#include <unistd.h>
#include <string.h>
int main(void) {
char aString[200];
char *stringPtr = aString;

[Code] ....

and these are my errors

212Untitled1.cpp[Error] stray '222' in program
212Untitled1.cpp[Error] stray '' in program
212Untitled1.cpp[Error] stray '222' in program
262Untitled1.cpp[Error] stray '222' in program
262Untitled1.cpp[Error] stray '' in program
262Untitled1.cpp[Error] stray '222' in program
Untitled1.cppIn function 'int main()':
2125Untitled1.cpp[Error] 'n' was not declared in this scope

View 3 Replies View Related

C++ :: How To Hide Password Entered By User

Jul 28, 2014

I'm making a Project on a Travel Agency and I need to hide the password entered by the user! I am working on Xcode 5.1.1 -> Command Line Tools -> C++ on my MacBook Pro! Here is what I've tried --

string pass ="";
char ch;
cout << "Enter pass";
ch = getchar();
while(ch != 13){//character 13 is enter

[Code]...

But in the first case the display is -

//Assuming the password is Hello Hello ******

And in the second its giving me 3 errors -

1. Apple Mach-O Linker(Id) Error "_stdscr", referenced from:

2. Apple Mach-O Linker(Id) Error "_wgetch", referenced from:

3. Apple Mach-O Linker(Id) Error clang: error: linker command failed with exit code 1 (use -v to see invocation)

View 10 Replies View Related







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