C :: Output Smallest Integer Entered - Loops / Function

Oct 22, 2014

I am trying to find a way to put a getSmallest function in here so that it will output smallest integer entered. If it is just an arbitrary amount of #'s and I don't know what will be entered I am confused. Both on how to do it and how to link my function to my loop.

Code:
/* Prompts user and gets integer numbers from keyboard, one number at a time. Ends program when 99999 entered. and displays various results.
Written by:
Date: 10/20/14
*/
#include <stdio.h>
#include <stdlib.h>

[Code] .....

Could I take this and just replace all variables a, b, and c with getNumber, where would I link/declare smallest?

Code:
/* ==================== smallest ======================
This function returns the smallest of 3 integers.
Pre given 3 integers
Post the smallest integer returned
*/
int smallest (int a, int b, int c) {

[Code] ......

View 1 Replies


ADVERTISEMENT

C :: Find The Largest And Smallest Number Entered By User?

Mar 6, 2015

How to find the largest and smallest number entered by a user. So far I'm able to add, find the average and count how many numbers are entered.

I'm just having trouble with find the max and min. I tried if statements and it breaks the program will it wont let me exit the while loop or the program will do a force close after entering a value.

Code:

#include <stdio.h>
#include <stdlib.h>
int main(){

int maxNum=0, minNum=0, value, count=0, sum=0;
double average;

[Code] ....

View 4 Replies View Related

C++ :: Finding The Largest And Smallest Integer In A Set Using While Loop

Sep 29, 2014

I've been working at this for awhile and it seems like it should be correct but it isn't giving me the desired output. Here's my code.

#include "stdafx.h"
#include <iostream>
#include <fstream>
#include <iomanip>

[Code]....

And here is my output when I run the program.
75
Max: 90
Min: 0

Press any key to continue . . I am reading from a file in this program which contains a set of 30 numbers and it has the average correct and the max correct but the minimum number in the set is 56 however it keeps giving me a zero for the min.

View 4 Replies View Related

C :: Integer Sum Using For And While Loops

Mar 6, 2015

I have an assignment that calls for a C program using a for loop AND a while loop that will receive an integer (called daNumba) and double it -- Using the integer the program will call the sumFor function and then the sumWhile function. These functions will both sum the values from daNumba to (daNumba * 2) ifdaNumba is positive. If daNumba is not positive it will add the values from (daNumba*2) to daNumba. Both functions will receive the value of daNumba and return a summed value. The only difference between the 2 functions is that sumFor will only use for loops and sumWhile will only use while loops. We are not to use arrays.

The program compiles without error. So far my while loop works for positive integers, but not with a negative integer (I have it commented out) I cannot get the for loop to work properly This is what I have so far -- I am stuck....

Code:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main () {

[Code] ....

View 12 Replies View Related

C :: Check If Input Is Integer Using Only Loops?

Nov 3, 2013

I have a homework that needs to verify if the input of the user is an integer using only loops no if statements Here's the problem:

A program is required that prompts the user for a number. The program will then print a series of asterisks to represent the number. If the user enters a number less than 1, the program stops. For example:

Enter a number: 5
*****
Enter a number: 3
***
Enter a number: 9
*********
Enter a number: 0

All user input must be validated:
- Check for non-numeric input when reading numeric input
- Check that values entered are within the expected range for their purpose, or in range based on the requirements statement

View 10 Replies View Related

C++ :: Sum Of Digits Entered And Output

Feb 25, 2014

A problem that lets the user enter any positive integer, but you do not have to check for this, and then calculates the sum of the digits and displays this to user. For example, if user enters 14503, the outputted sum of the digits would be 13. You need turn in an algorithm, C++ source code and output.

how do i even go about making 1 add to 4? and so on. I'm lost.

View 5 Replies View Related

C++ :: How To Stop Input Process When Five Negative Integer Entered

Jul 25, 2014

int a[20],x;
for(x=0; x<20; x++)
{

[Code]....

This should be the output

Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: 1
Input: -1
Input: -1
Input: -1
Input: 1
Input: -1
Input: 1
Input: -1

Stop!

View 5 Replies View Related

C :: How To Output The Last Positive Number Entered

Jan 25, 2014

Create a program that keeps on reading positive numbers until user enters a zero value, and then outputs the last positive number entered.

I do not know how to output the 'last positive number' and I do not even know am I doing things correctly so far....

Code:
#include <stdio.h>
int main() {
double num;
for(;;) {
printf("Enter a positive number: ");
scanf("%lf",&num);

[Code] ....

View 9 Replies View Related

C++ :: Program To Display Error Message If Variable Entered Not An Integer

Nov 8, 2013

I need to have a program display an error message if the variable entered isn't an integer but then I want it to cin again. I have this but it doesn't work:

cout << "Enter an Integer: " ;
for (;;) {
cin >> var;
if (!cin) {

[Code] ....

I am not sure how to do what I want and this doesn't work, it just repeats That wasn't an int.. over and over again.

View 8 Replies View Related

C++ :: Output Multidimensional Array Using For Loops

Feb 12, 2013

In the code that I am working on I am generating random numbers and assigning them a 2d array. But when I output the array in a separate nest of for loops the values are incorrect, but if I output the array in the same nest of for loops the values are correct

int spot[4][4];
int range[] = {1,16,31,46,61}, held[4];
void Generate() {
for (int y =0; y<=4; y++) {
for ( int x =0; x<=4; x++) {
spot[x][y] = (range[x] + rand() % 15);

[Code] ....

View 3 Replies View Related

C++ :: Mixed Expressions / Loops And Formatted Output

Feb 22, 2015

1) ask the user to input a mathematical expression in the following format:

NUMBER Operator NUMBER Operator NUMBER
Example: 17 + 15 - 3
Example: 2 * 3 - 4

How to output the answer of the users equation. Is there a function that includes all math operators (+,-,/,*)? Would i need to write each possible scenario using if statements?

View 2 Replies View Related

C# :: For Loops To Make User Defined V Shape Output

Jul 29, 2014

Write a program to ask a user to input a symbol from the keyboard and to output that symbol in a n X n/2 sized V where n = the width of the V. You must use a loop to process the data

I am stuck at trying to figure out how to do the actual output formatting. This is where I am sitting currently.

string character = "";
int vheight = 0;
Console.WriteLine("Enter the character you wish to use for your V: ");

[Code]....

so Im really just a bit stumped on how to get the actual V shape to be formatted..

View 14 Replies View Related

C :: Function Call To Print Smallest Number?

Mar 15, 2013

C programming, make it use a function call to print the smallest number? this is a program which prints out the smallest of three numbers within the main function that I was asked to write.Now the other question i am asked,5. Re-write the program, uses a function call to print the smallest number?

Code:

# include <stdio.h>

main()
{
int a,b,c;
int temp, min;
a = 100;
b = 23;
c = 5;
}

[code]....

View 5 Replies View Related

C++ :: String Integer Value - Input / Output

Aug 14, 2013

Code:
Prompt the user to input a string,
and then output the sum of all the digits in the string.

Sample Run 1:
Input -> A111B222C
output -> 9

Sample Run 2:
Input -> ABC123XYZ32100000005555555555zzzzzz
output -> 62

View 1 Replies View Related

C :: Compute Permutations Of Any String Entered - Function Will Not Return A Value

Jun 11, 2013

This is my program, for now it is intended to compute permutations of any string entered, but the function ox will not return the final x value. ox is the function that actually computes the permutations so the return of the x value is critical.

Code:
#include<stdio.h>
#include<string.h>
int ox(int x);
int main() {
int x;
char input[10];

[Code] .....

View 2 Replies View Related

Visual C++ :: Backward Function - Reversing Words Entered?

Apr 21, 2013

My program , it says there is no problem with the build but when exe. it displays a bunch of backward 'k' instead of reversing the words entered.

Problem: Enter in a C-string and use function to display the word backward. (it might work with a pointer but I am not sure how to go about it)

lab10_p2.cpp

View 4 Replies View Related

C :: Passing Array To A Function - For Loops?

Aug 17, 2013

I have tried to pass an array to a function. Why my code doesn't work for a[1][0], a[1][1] etc.

Code:
#include <stdio.h>
int i=0;
int j=0;
int main(void){
int a[3][3]={1,2,3,1,2,3,1,2,3};
void f(int a[3][3]);

[Code] ....

I think my problem is with the for loops. I will try to find the error a bit more.

View 6 Replies View Related

C++ :: Accept Signed Decimal Integer As Input And Output In Binary

Jan 29, 2015

Write a C++ application program to accept a signed decimal integer as input and output the equivalent 2s complement version in 16-bit binary. Include a space between every four bits in the output string. The input will only be processed by the application if it falls in the valid range that can be represented in 2s complement format with 16 bits. The range of a decimal number from - to + is -32768 to 32767.

View 3 Replies View Related

C++ :: Function To Count Digits Of Entered Number Doesn't Work

Feb 19, 2013

I wrote a program with function my own function which count the digits of entered number. The problem is whatever i type it shows 0 digits.Why is that?

Code:
#include <iostream>
using namespace std;
int cikCipari (int skaitlis, int cipars);
int main()

[Code] .....

View 7 Replies View Related

C++ :: Function That Makes Shows Time Entered In Clock Format

Mar 11, 2014

Program should continually have user enter a positive integer, and quits on zero entered. This entered number represents the total number of seconds and after each number is entered a function is called that displays the time in hours, minutes and seconds. Sample output is as follows:

Enter Total Seconds --> 3605 1:00:05

The function needs only one value parameter and should return nothing back to main. If the minutes or seconds are a one digit number then make sure to display a leading zero as the example above shows.

Here is my program. my question is how do i make the numbers appear like this? 1:00:05

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

[Code].....

View 6 Replies View Related

C/C++ :: Multiple For Loops - Independent Function Change

Feb 28, 2015

I'm new to writing C. While doing for loops I have found that when I try to do functions and have multiple for loops, even though I have different counters, the independent functions change. For example:

int factorial(n) {
for(i=1;i<n;i++)
fact=fact*i;
return fact;

[Code] ....

The cosine function works out fine but the factorial one spits out crazy numbers, more specifically, 6^1 through 6^10. In my head, the factorial should be a constant throughout the second loop for I guess I am wrong. Why this happens?

View 6 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++ :: Input Integer Then Output Both Individual Digits Of The Number And Sum Of Digits

Oct 11, 2014

My problem needs to prompt the user to input an integer and then outputs both the individual digits of the number and the sum of the digits. An example would be entering 8030 and it spits out 8 0 3 0 as well as 8+0+3+0=11 and it needs to work with negative numbers.

Code:
#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int base;

[Code] ....

Now I don't know if any of this is right a hint my professor gave us is that to get the fourth digit you would do base mod 10 and to get the first digit you do base divided 1000...

Code:

{
int power;
int counter=0;
int value=1;
cout << "Enter the power of 10 you want: ";

[Code] ....

View 2 Replies View Related

C :: Display Function Displays All Letters Of Word Entered Instead Of Word Itself

Feb 18, 2013

I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.

Code:

//-----------struct ------------//
struct Node
{
char data;
struct Node *next;
}*Head;

[code]....

View 1 Replies View Related

C :: Getting Integer With Only Using Getchar Function

Nov 16, 2013

I need to get an integer number with only using getchar() and without pre knowing the number of digits in the integer. And I cannot use strings or arrays.

View 4 Replies View Related

C++ :: Why Function Is Not Returning Integer 1 Or 0

Nov 14, 2013

why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/

#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));

[code].....

View 2 Replies View Related







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