C++ :: Number Sorting Program - Getting Correct Numbers

May 10, 2014

I am a beginner at C++, the output is pretty self explanatory. I'm trying to make a number sorting program with other features, but the numbers are all wrong.

Code:
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;

[Code] .....

Input.DAT
Code:
376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421

I can't for the life of me figure out why the numbers are all messed up.

View 5 Replies


ADVERTISEMENT

C++ :: Getting Correct Numbers After Sorting

May 10, 2014

I'm trying to make a number sorting program with other features, but the numbers are all wrong.

#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void readData(int list[], int size);
int main() {
int size = 50;
int scores[50] = {0};

[Code] ....

Input.DAT

376 389 450 735 600 576 612 700 450 628 778 389 667 500 475 550 687 791 829 344
549 476 400 587 535 657 789 583 340 764 422 826 566 436 565 834 533 423 837 701
847 521 746 356 582 465 493 593 425 421

View 2 Replies View Related

C/C++ :: Sorting Program That Sorts Numbers From Least To Greatest

Jul 5, 2014

I have to write a program that sorts numbers from least to greatest. The way that it has to sort them is:

1) The program assigns the first number to be a minimum
2) If the next number is less than the minimum is now that number and they switch places. (We keep on looking if the number next to it is not smaller)
3) The program also gets the index of the minimum number
4) We keep on going until it is in order.

// Sort.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <iostream>
#include <vector>
using namespace std;
void Sort(vector<int>&input);
int _tmain(int argc, _TCHAR* argv[]){
vector <int> input;

[Code] ....

View 4 Replies View Related

C++ :: Don't Give Correct Location Of Max / Min Number In Array

Nov 8, 2013

All my code is good, except the functions: findMacLoc and findMinLoc .They don't give me the correct array location of the max/min number in the array.I know is something simple I need to tweak in those two functions.

#include <iostream>
#include <time.h>
using namespace std;
void printArray(int a [], int & size)
{
int i;
for (i = 0; i < size; i++)
cout << a[i] << " ";

[code].....

View 2 Replies View Related

C++ :: Math Tutor - Guess Correct Answer Of Random Numbers

Jul 11, 2014

Objective: Guess the correct answer of the random numbers

Problem: I guess the correct answer but the program keeps telling me that I'm INCORRECT.

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char * argv[]) {
const int MIN_VALUE = 1; // Constants
const int MAX_VALUE = 200;

[Code] ....

View 2 Replies View Related

C++ :: Program Which Print Out All Prime Numbers Less Than Or Equal To Given Number

Nov 11, 2013

how to make a programm in native c++ which print out all prime numbers less than or equal to given number????????

View 5 Replies View Related

Visual C++ :: Nim Project - Not Displaying Matches But Display Correct Number

Apr 9, 2013

I am having one issue with my project. We are making a game of Nim code.I'm 99% done with it, i worked hard on it and i feel like i did a good job, however my project is not displaying the matches i want. For example, it display's the inital number of them 23. But once the first player subtracts a number, it doesn't display matches for player 2, just the number of matches remaining. Then as i keep running the program the same thing happens. This is what it's supposed to
output:

"Input/Output sample
WELCOME TO NIM
------- -- ---
Enter the starting player's name (no spaces)-->John
Enter the second player's name (no spaces)-->Mary
There are 23 matches.
ooooooooooooooooooooooo
|||||||||||||||||||||||
Player John please enter the number of matches to remove-->2
There are 21 matches.
ooooooooooooooooooooo
|||||||||||||||||||||
Player Mary please enter the number of matches to remove-->3
There are 18 matches.
oooooooooooooooooo
||||||||||||||||||
Player John please enter the number of matches to remove-->1 "

This is entire code.

#include <iostream>
#include <string>
using namespace std;
int main() {
// Holds variables.

[Code] ....

I will attach my code as well.ProjectNim.cpp

View 7 Replies View Related

C++ :: How To Correct The Search In The End Of Program

Jun 1, 2013

Code:
#include<conio.h>#include<iostream.h>
class air_line {
private:
char name[5][100],name1;
long double opt,opt1,opt2,cnic[5],ticket_number[5],ticket_number1,cnic1;
public:
void input()

[code].....

View 1 Replies View Related

C :: Sorting Four Numbers

Mar 2, 2013

I'm trying to take a users input and break it up into four separate numbers, then take those numbers and arrange them from smallest to largest.So far I can't seem to get them working right.

Code:

# include <stdio.h>main ()
{
int inputVariables[4]; //where userinput goes after being broken up
int arrangedValues [4];// the user values arranged lowest to highest
int i;
int j;
}

[code].....

View 4 Replies View Related

C++ :: Program To Output A Check With Correct Spacing

Oct 14, 2013

So I have to write a program that outputs a check with correct spacing and everything.

Create a project titled Lab7_Check. Write a program that asks the user the check information and prints the check. The dialog should be as follows:

date: 2/23/2010
name: William Schmidt
amount, dollars: 23
cents: 30
payee: Office Max

your check:

William Schmidt 10/13/2013
pay to: Office Max $23.30
twenty three and 30/100 dollars

You may assume that a person always has the first name and last name (no middle names or initials). The payee name is also always two words. The dollar and cent amount are integers and the amount is always less than 100 dollars. Note that the dollar amount could be zero, in which case, when you spell the dollar amount, it should print "zero". The date is always a single (non-white space separated string). Your date, dollar amount in numbers and the word "dollars" have to vertically align.

This is the code I have so far.

#include <iostream>
#include <string>
using namespace std;
int main(){
string date;
string firstname;
string lastname;

[Code] .....

View 3 Replies View Related

C++ :: Sorting Numbers From File

Apr 6, 2013

I have been working on this program for days now and for some reason my program will not write to my third file. It will call all of the integers that I need it to call but it will not write them out to a file. How to use my loop correctly.

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

int file1();
int file2();
int file3(int);

[Code] ....

View 10 Replies View Related

C++ ::  Sorting Pairs Of Numbers Using AMP

Dec 15, 2014

I need numbers next to each other to be sorted (in increasing order).On the CPU I'd do something like this:

for(int i=0; i < length; i+=2) {
if(a[i]>a[i+1]) {
switch places...
}
}

But how would I do this using parallel_for_each (C++AMP) ? I need this for some algorithm that works with very long arrays and I think GPU would do this faster than CPU (even if I use all threads).

View 3 Replies View Related

C++ :: Sorting Alphabets And Numbers

Apr 20, 2014

My program reads a string of characters. Prints all occurrences of letters and numbers, sorted in alphabetical and numerical order. Letters will be converted to uppercase.Other characters are filtered out, while number of white spaces are counted.

The problem is it crashes when i run the program. Here is my code

#include <iostream>
const int SIZE = 100;
using namespace std;
int main() {
char *pStr, str[SIZE] = "", newStr[SIZE] = "", ch;
int count = 0, i = 0, j;

[Code] .....

View 5 Replies View Related

C/C++ :: Sorting Numbers Through Pointers?

May 5, 2014

I'm writing a simple program to sort numbers through use of a pointer. I've always been bad with pointers, and I tried to use a typical temp value to hold the value, but i feel like I am over doing it.

#include <iostream>
using namespace std;
void SortTests(int *, int);
int main() {
int *ptr;
int tests;

[code]....

View 2 Replies View Related

C++ :: Sorting Names And Numbers And Also Using Templates

May 7, 2013

For my project I have to sort 5 numbers and 5 names using a template bubble sort. I have one header for the numbers, and one for the names. This is what I have so far for my testing page:

#include "Floatheader.h"
#include "Nameheader.h"
#include <string>
int main ()
myFloat obj1;
myFloat obj2( 2.2, 5.1);

[Code] .....

I have to create a template to look like this: template<>....with a class inside the arrows. Then, I have to use bubble sort to sort the 5 names and number objects I have created. Sorting the names and numbers and also using templates?

View 1 Replies View Related

C++ :: Sorting 3 Numbers By Ascending Orders?

Jan 30, 2015

We've only covered up to Functions and how to use reference variables inside the function parameter.

One of the hw problem that was assigned was to write a void function that takes three parameters( num1, num2, num3) by reference and sorts their values into ascending order, so that num1 has the lowest, num2 the middle value, and num3 the highest value. For example, if user enters: 14, -4, 8, then the output should look like this:

-4
8
14

I've completed the program with a bunch of if/ else if statements but I was wondering if there was a more efficient way to sort the numbers. Bear in mind, we've only covered materials up to functions so I can't use any other new techniques that we haven't cover yet. Here is my code:

// This program will take three int parameters by reference and sorts their value into ascending order
//so that num1 has the lowest value, num2 has the middle value, and num3 has the highest value
#include <iostream>
using namespace std;
// declare function with reference parameter that with sort numbers
void sortNum(int &, int &, int &);
int main ()
{

[Code]....

View 2 Replies View Related

C++ :: Quiz Program - Checking Whether Entered Answer Is Correct From A File

Apr 15, 2014

My code is not moving past the line below...actually i am making a quiz and this piece of code id checking whether the entered answer is correct, from a file..

getline(anss,saveans);
while(a<1) {
getline(anss,saveans);
if (saveans == ToString(randNum)) {
getline(anss,saveans);
if (saveans == ans)

[Code] ....

View 9 Replies View Related

C++ :: Sorting Numbers In Both Ascending And Descending Order?

Sep 7, 2014

What kind of code should i use for sorting numbers in both ascending and descending order? I don't know how to use bubble sorting either, is there another easy way to sort this out?

View 3 Replies View Related

C++ :: Sorting Arrays - Int Numbers From Highest To Lowest

Oct 29, 2014

For my program i need to sort my int numbers [5] from highest to lowest but it seems that i made it go from lowest to highest ...

Code:

#include <iostream>
using namespace std;
int main() {
int numbers[5] = {3, -6, 10, 1, 130};
int counter1, counter2, tempNum;
//Highest to Lowest

[Code] ....

View 1 Replies View Related

C/C++ :: Sorting Numbers In Array From Largest To Smallest?

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

C/C++ :: String Of Characters - Sorting Alphabets And Numbers

Apr 20, 2014

My program reads a string of characters. Prints all occurrences of letters and numbers, sorted in alphabetical and numerical order. Letters will be converted to uppercase.Other characters are filtered out, while number of white spaces are counted.

the problem is it crushes when i run the program

Here is my code

#include <iostream>
const int SIZE = 100;
using namespace std;
int main() {
char *pStr, str[SIZE] = "", newStr[SIZE] = "", ch;
int count = 0, i = 0, j;

[Code] .....

View 1 Replies View Related

C++ :: Prime Number Program Not Working With Odd Non-prime Numbers

Dec 2, 2014

I have a program that gets prime numbers that doesn't work. It looks like it works for all prime numbers except odd non-prime ones. Here is the code:

Code:
#include <iostream>
using namespace std;
bool isPrime(int prime) {
while(true) {
int track = 0;

[Code] ...

View 3 Replies View Related

C++ :: Sorting Large Numbers Of Vector Of Random Integers Returns All Zero

Jul 31, 2014

I tried to sort a large numbers of vector of random integers with std::sort(), but when the number increases over 10M, std::sort returns all zero in values. Does std::sort have a limitation of input numbers?

View 1 Replies View Related

C :: Sorting Number As A String By Ascending Order

Jul 2, 2014

make my program sort data.in this case number that i declared as char(not string, my bada)if i have

name1
number 2500
email

name 2
number 2400
email

i need to put that this way:
name 2
number 2400
email

name1
number 2500
email

i saw that can be done with qsort but when i try it it doesn't work.

Code:

typedef struct {
char nome[MAX_GERAL], email[MAX_GERAL], morada[MAX_GERAL], postal[MAX_GERAL], numero[MAX_GERAL], geral[MAX_GERAL];
int telefone, FP, SD, AM1, ALGA, CM;
}dados;

code to add info i need to sort "numero"

Code:

void adicionar(dados* contacto){
if (i<total) {
printf("
Introduza o Nome: ", i + 1);
scanf(" %[^

[code]....

View 7 Replies View Related

C :: Break Statement In Random Number Sorting

Jul 4, 2014

The program I am stuck on is used to generate random numbers, then sort them (found in Chapter 23, p. 212). When I compile it, I get an error stating "break statement not within loop or switch. I'm finding that there is an issue with a break statement, but I don't know enough yet.

Code:
/* Will generate random numbers, then sort them.*/

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

main() {
int ctr, inner, outer, didSwap, temp;
int nums[10];
time_t t;

[Code] ....

View 4 Replies View Related

C++ :: Import A File Containing Words And Numbers To Linked List - Bubble Sorting

Feb 16, 2013

I have a code able to import a file containing words and numbers to a linked list, but I also need to sort this linked list alphabetically. I've done research on this involving bubble sorting, but no explanationcan achieve this objective.

Below is the code that can only put the file into linked list:

Code:
#include<iostream>
#include<conio.h>
#include"U:C++WordClass2WordClass2WordClass.cpp"
#include<fstream>
#include<vector>
#include<string>
using namespace std;

[Code] .....

View 5 Replies View Related







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