C :: How To Scan In Numbers From File And Find The Largest
Oct 4, 2013
I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.
input file text (first number is num of auctions, after that it's num of bids, then the bids):
5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23
Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!
The silent auction raised $2470.00 for charity!
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
[Code].....
View 4 Replies
ADVERTISEMENT
May 30, 2014
I seem to have reached a dead end in a program I am attempting to write.The purpose of the program is find the smallest, largest, and average values in a collection of N numbers. It needs to get the value of N before scanning each value in the collection of N numbers.I'm having trouble creating comparisons for each set. I have a feeling because of the way I structured my program, I'm unable to make a proper comparison. Maybe my approach was wrong as soon as I got to the for statement to loop N sets and N numbers.Here is my code so far:
Code:
#include <stdio.h>
int main (void)
{
int num_sets, num_of_integers;
int count, count2, set, sum = 0;
int num, avg;
}
[code]....
/* Here is where I would continue to attempt to make a comparison between sets to determine smallest to largest */
return 0;
View 5 Replies
View Related
May 13, 2014
im trying to write a source code that find the smallest, largest and average of numbers in array. the code runs fine, but it is not giving the highest number and the the average should include only four number excluding highest and smallest number from the array.
void OlympicJudging() // Olympic Judging {
int numbers [6];
double average, sum = 0;
int temp;
for(int i = 0; i < 6; i++){
cout << "Please type a value for scores: ";
cin >> numbers[i];
[Code]...
View 5 Replies
View Related
Jan 30, 2013
find inserted numbers, let say 10 numbers and find the largest and second largest number with their position in an array?
View 3 Replies
View Related
Apr 28, 2014
Write a program that uses two functions; one finds the largest number and second largest number; and second function finds the average. The data, comprising of 20 different temperature values, is available on a file.
View 1 Replies
View Related
Oct 15, 2012
there is a file contains only a numbers ,we dont know how many numbers present in that file.so i want a program to display top n largest number present in that fie.(n may be 5,10,12 like that.)
View 3 Replies
View Related
Feb 3, 2015
I need a code that will search through string 1 and find the first place with a letter that also appears in string 2 and return the pointer of that place. This is what I wrote:
char strPbrk(const char *s1, const char *s2) {
char p = *s1;
for (int i = 0; i < strlen(s1); i++)
for (int j = 0; j < strlen(s2); j++)
if ((p+i) == *(s2+j))
return p;
return NULL;
}
but it continues to return wrong values idk what I'm doing wrong.
View 4 Replies
View Related
May 17, 2013
i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:
Code:
float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);
The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.
how to scan numbers into an array so that they can be used for later use?
View 9 Replies
View Related
Jul 26, 2013
Its a code to find the largest number of a 3X3 matrix.The logic seems to be right........
Code:
#include<stdio.h>
main() {
int matrix[3][3],i,k,j,*a;
a=&matrix[0][0];
printf("Enter the elements");
for(i=0;i<=2;i++) {
[Code]....
View 7 Replies
View Related
Oct 18, 2014
Write a program that will find the smallest, largest and average of the values in a collection of N positive integer numbers.
View 12 Replies
View Related
Apr 19, 2013
I have a std::map<int, foo>
what's the ideal way to get an iterator to the item that has the largest key (int) smaller than a given value.
basically, the item before upper_bound(). I can use upper_bound() and then decrement, but it needs special cases for both end() and begin(), and in the case of end() I'm not sure how I get it to the last item in the map, afaik, we're not allowed to decrement end().
Code:
auto it = mymap.upper_bound(x);
if (it==mymap.begin()) // first item in the map is already too large. reject
NotFound();
else if (it==mymap.end())
[Code] .....
// here it points to largest item smaller than x.
I can iterate over the entire map and do a compare, but then I pretty much loose the benefit of the binary search.
View 2 Replies
View Related
Aug 30, 2013
While finding the primes , I do not know how to make it into one array so that...
View 7 Replies
View Related
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
Feb 27, 2013
I made the code that stores and prints 5 row by 5 column values but how to find the largest number from them.What should I do to find the largest number?If I use if-else then it would be very tedious but I think there is way out with for loop but still I can't frame the logic. Here is the code
Code:
#include<stdio.h>
main() {
int lnum[5][5];
int i,j;
for(i=0;i<=4;i++) {
[Code] .....
View 7 Replies
View Related
Apr 6, 2015
How to find triangle in an array of n triangles which has the largest area?
#include <stdio.h>
#include <stdlib.h>
#include<math.h>
typedef struct {
double x,y;
[Code] .....
View 14 Replies
View Related
Nov 16, 2013
I am writing this code, and I every time I run question A, no matter what numbers I put in, I get "larger = 0.
#include <iostream>
using namespace std;
int awesome ();
int best ();
int crazy ();
int main () {
char letter;
int smallestNumber;
int largestNumber;
[Code] .....
View 2 Replies
View Related
Sep 29, 2013
Thing I want is find the largest sum down a triangle,(moving to adjacent numbers on the row below )there are many methods to go down.
75
95 64
17 47 82
18 35 87 10
20 04 82 47 65
19 01 23 75 03 34
88 02 77 73 07 63 67
99 65 04 28 06 16 70 92
41 41 26 56 83 40 80 70 33
41 48 72 33 47 32 37 16 94 29
53 71 44 65 25 43 91 52 97 51 14
70 11 33 28 77 73 17 78 39 68 17 57
91 71 52 38 17 14 91 43 58 50 27 29 48
63 66 04 68 89 53 67 30 73 16 69 87 40 31
04 62 98 27 23 09 70 98 73 93 38 53 60 04 23
I wrote a program with a recursive() called finder. But it dose not work properly,at run time it becomes to a infinite status. How to detect the error at runtime. Here is the code.
#include<stdio.h>
void finder(int x,int y);
int tot;
[Code] ....
I think the error is the changing value of x after a round of for loop.
View 2 Replies
View Related
Mar 25, 2013
I'm trying to find the two largest numbers out of ten. I've re-done this problem several times and it still doesn't work.
Code:
#include <stdio.h>
int main(void) {
float number;
float largest;
float secondLargest;
float counter;
float temp;
}
[code]....
View 9 Replies
View Related
Oct 9, 2013
My display is producing:
Enter the first number:234
Enter the second number:2
Enter the Third number:3
The largest number is 3
#include <iostream>
using namespace std;
double larger(double n1, double n2, double n3);
int main() {
[Code] ....
View 1 Replies
View Related
Feb 6, 2015
#include<iostream>
using namespace std;
int computeTotal();
int findSmallest();
int findLargest();
[Code] .....
View 4 Replies
View Related
Jan 3, 2014
I have a list of numbers with decimal point saved in a text file (grade.txt) like this:
80.2
85.7
57.2
90.0
92.9
74.0
76.5
...
I would like to write a small program to display the top 10 highest and lowest grade points.
View 3 Replies
View Related
Dec 2, 2014
The only part I have working is getting all odd random numbers but the logic in getting the largest and smallest from random is what is giving me alot of trouble.
class Program {
static void Main(string[] args){
int num = 0;
int largest = 0;
Random rand = new Random();
for (int ctr = 1; ctr <= 100; ctr++)
[code]....
Console.Write("{0,5} The larget number out of 100 odd numbers is: {1:n}",y,largest);
View 4 Replies
View Related
Mar 16, 2014
I'm trying to sort the numbers in an array from largest to smallest and print it but whenever I run this it does not sort anything at all.
#include <stdio.h>
#define SIZE 10
void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);
size_t counter1 = 0;
int average;
int main( void ) {
int array1[ SIZE ];
[code]....
View 4 Replies
View Related
Mar 4, 2013
This is my text file.
bak kut teh[tab]888.0[tab]989.0
spicy chicken nugget[tab]999.0[tab]978.0
I'm experiencing some problem in trying to scan and put it into an array for the food names (e.g an array for food which consist of bak kut teh and spicy chicken nugget) and another 2 array for the other individual integer into C. However there seem to be some problem with my code.
Is there a difference if I use both tab and space instead of space for all?
Code:
#include<stdio.h>
int main() {
FILE *fp;
char food[100];
char buff[BUFSIZ];
float num;
[Code] ....
View 2 Replies
View Related
Nov 18, 2013
I am trying to Write a program that inputs three integers from the keyboard and prints the sum, average, product, smallest and largest of these numbers. How do i go about it. What i dont know is how to come up with smallest and largest number .
View 1 Replies
View Related
Jul 29, 2013
I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.
This is what I have ....
#include <iostream>
using namespace std;
int main() {
int amount;
int count;
int number = 0;
int smallest = 0;
int largest = 0;
cout << "Enter total numbers to process: ";
[Code] ....
View 4 Replies
View Related