C++ :: Multiply Number Of Seat And Ticket - Return Value Not Working

Dec 20, 2013

I have a code in here that u will multiply the number of seat and the number of ticket. I think I got the correct return value but it's still not working when i times it it always = 0 ...

#include<iostream>
#include<iomanip>
#include<string>
#include<stdio.h>
#include<fstream>
int getBill(int seat);
int getPos(char seat);

[Code] ....

View 14 Replies


ADVERTISEMENT

C/C++ :: How To Change Seat Reservation

Jun 9, 2014

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

int main(void) {
char answer;//예약 선택
int select1 = 0, select2 = 0, i, j;//필요 변수 선언
int seat[5][5] = { 0 };

[Code] .....

well this is my seat reservation code and my program show the seats like

1 1 2 3 4 5
2 0 0 0 0 0
3 0 0 0 0 0
4 0 0 0 0 0
5 0 0 0 0 0

I want to change these numbers to "■" and "□"(when it's empty seat)

View 1 Replies View Related

C/C++ :: Sorting Airplane Seats And Their Passengers By Seat Order?

May 2, 2014

The assignment is to read in a text file of passenger names (first and last initial), seats (A1, B1, C1, D1, A2, etc.), and ticket prices. The output is specified to be a table of passengers and their seats sorted by seat order, and I also have to print the minimum and maximum ticket prices along with the owner of each ticket, along with the average of all ticket prices. My arrays are all reading in correctly, and the minimum, maximum, and average ticket prices were all easy to find. My problem is the sorting.

We were introduced to arrays a couple weeks ago and this is our first time doing any sorting. We are supposed to use a bubble sort, and while I think I gather how to use a bubble sort, it's not working in my program (so obviously I don't really know how to use it). I have tried several different things, and sometimes a few seats/names will switch around (never the way I want them to) and sometimes nothing will happen at all.

New to programming, not trying to get homework done for me, need to bubble sort airplane passengers and seats by seat order (A1, B1, C1, D1, A2, etc).

My input looks like this:

A Z A1 555.55

repeat with different initials, seats, and prices however many times the user sees fit.

I have a 1D character array for the columns(A - D), a 1D integer array for rows (1 to maximum integer), 1D float array for prices, and 2D array for name initals.

Here's the function to read in the arrays:

void read_Arrays(char seat_cols[], int seat_rows[], char name[][LAST], float price[]) {
int i, j;
for(i = 0; i < FIRST; i++) {
for(j = 0; j < LAST; j++) {
scanf(" %c", &name[i][j]);
} scanf(" %c %d %f ", &seat_cols[i], &seat_rows[i], &price[i]);
}
}

Here's the sort. The way we were shown to do it was with a 'for' loop nested within a 'do while':

{
do {
flag = 0;
for(i=0; i < ROWSIZE-1; i++) {
if(seat_rows[i] > seat_rows[i + 1]) {

[code]....

View 6 Replies View Related

C++ :: If Statement To Read Number Negative Or Positive Not Working

Nov 10, 2014

So I tried creating a test code for reading a negative number and positive number but whenever I enter a negative number it read it as being positive.

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

[Code].....

PS: I am using char over int because the program that I am testing for requires me to use 8 bit variable.

View 2 Replies View Related

C++ :: Random Number Generator Isn't Working Correctly - Ignoring Conditions

Apr 12, 2014

My random number generator isn't working properly. It seems to be ignoring my conditions when it compiles and I enter the input. The program is supposed to accomplish the following.

1. Let the user input how many digits he or she would like to have in the random numbers.

2. Let the user type in how many of the numbers that he or she wants.

3. It will then generate the numbers.

4. It will display the minimum or maximum number it can be with the number of digits the user entered. And display the number of numbers that the user wanted. It also is supposed to check and output only up to the max of that digit range.

so if someone entered they wanted a digit of 1(1-9) but said they wanted 300 numbers it would only output 9

Example:
the user says that she would like 3 digits to be in the numbers generated. So it will output numbers between 100 and 999. then the user says that they would like only 3 random numbers. So it will output three random numbers in between 100 and 999. Also all of the numbers need to be unique so they can't output more then one of the same number.

I am not sure why but it ignores my conditions. Ill type that I want 7 but it just outputs a bunch of random numbers. it dosen't stay in the ranges.

Class file.

Code:
#include "stdafx.h"
#include <fstream>
#include <iomanip>
#include <iostream>
#include <string>
#include <conio.h>
#include "TargetGen.h"
using namespace std;

[Code] .....

View 6 Replies View Related

C :: Get Binary Number And Change Its Bits - Calling A Function Not Working

Apr 8, 2013

This code gets a binary number and change its bits. I have a problem with the "bits_up" function . Why this function not working?

Code:
#include <stdio.h>
#include <stdlib.h>
int bits_up(uint first,uint last,int *ptr);
int main(void)
{
uint first,last,bitUD;
int InputBinNumber[4],updatedNum[4];

[Code] ....

View 5 Replies View Related

C++ :: Program To Allow A User To Input A Number From Keyboard That Involves Loop Not Working Right?

Mar 30, 2014

I'm trying to write a C++ program that will allow a user to input a number from the keyboard. Then using a loop, that will perform 10 times, multiply the entered number by the loop counter. Print out the loop counter, the entered number and the product of the loop counter and the entered number. A one-time heading should be displayed before information is printed.

This kinda of what I have so far:

#include <iosteam>
using namespace std;
int main () {
Start
Declare: numScores, sum, score, avg, SENTINEL = 200
numScores = 0

[Code] ....

All the programs I have tried to make are not working?

View 4 Replies View Related

C :: Return Number Of Bits Set To True

Jan 3, 2015

The task is to return the number of bits set to true.Here is my code:

Code:

int cardinalityBS(PBitSet _this) {
int s, counter = 0;
for(s = 0; s < 31; s++) {
counter += _this->bits & 1;
_this->bits <<= 1;
}
return counter;
}

[code]....

The code is not working, since whenever I set _this->bits to a number, it returns me the wrong result.

View 7 Replies View Related

C++ :: Random Number Generator - Return Value?

Oct 21, 2014

It seems as though my program is working great but I'm having problems with my random number generator. It keeps giving me a return value from the computer of scissors (or 3) for the computers random choice. What can I do?

//Purpose of Program: This program is meant to prompt the user to choose between 4 menu options.
// Each option will be the users choice of rock, paper, or scissors.
// the computer will then randomly generate a number and pit you against the computer.

#include <iostream>
#include <cstdlib>
#include <ctime>
using namespace std;

void user(int getUserChoice);
void comp(int getComputerChoice);
void winner(int UserChoice, int ComputerChoice);

[Code] ....

View 1 Replies View Related

C++ :: Make A Function To Return Placement Number

Mar 25, 2014

I have a class called items and stored in a vector as vector<items*> item.now I want to make a function to return the placement # that the item is stored at with a unsigned int. but if I don't find the item is there like a null unsigned int that can be returned.

unsigned int someFunc(vector<items*> item)
{
unsigned int size = item.size();
for (unsigned int i = 0; i < size; ++i)
{
if (item[i]->getItemName() == "sword")
{
return i;
}
}
//i need code here incase the item is not there
}

because the item might not be there and i would like to do a line if(unsigned int) do this code

View 19 Replies View Related

C++ :: Function Which Take An Integer And Return Number Of Digits In It

Jan 31, 2013

I want to write a function which take an integer and return the number of digits in it i.e

int i = 123456
func(i) {
some code
}

output
the number of the digits are 6

View 9 Replies View Related

C++ :: Return Maximum Frequency Number From Stack

Dec 17, 2013

I designed one mfc vc++application in which data received from udp is stored in file as well as in stack.I used stl for stack; it stored elements as per receiving order,but i want to return repetitive number from stack,how to use stack as function parameter & retrieve elements of stack as an array? I write code for push elements in stack given below.

<template< typename T > void pushElements( T &stackRef,int value) {
stackRef.push( value);
}/>

View 1 Replies View Related

C++ :: Program That Takes Two Complex Number And Return Their Sum?

Oct 25, 2013

you have been tasked to write a program that takes two complex number and return their sum.However the + operator will not worl with complex numbers and you figure you need to verload the + and the assignment opeartor=.Ypu have come across the program [URL]

implement it and the client code to see it rune for the following complex numbers:

c1=3.0-4i,c2=8+4i

i have 3 files,driver.cpp,Complexnumber.cpp and complexNumber.h

complex.cpp is as follows

#include <iostream>
using namespace std;
class ComplexNumber {
private:
double real;
double image;

[code]....

View 4 Replies View Related

C++ :: Remove / Rename Functions Works But Return Non-zero Number

Jan 13, 2013

My source works perfect.The problem is that the (remove(),rename()) functions works but return nonzero number, so they fails all the time.

#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <fstream>

using namespace std;
int main() {
char array[100]={"1)open-write,2)open-read,3)rename,4)delete"};

[Code] ....

View 1 Replies View Related

C/C++ :: Take In Unsigned Number And Afterwards Return N-th Member Of Recursive Function

Mar 14, 2015

I'm having an issue with the following assignment:

Program is supposed to take in an unsigned number and afterwards return the 'n-th' member of the following recursive function:

f(1) = 1, f(2) = 2; f(3) = 3; f(n+3) = f(n+2) + f(n+1) + f(n), n>0;

When I worked with Fibonacci it was pretty easy since I just had to decrement the next member for each step. I used the following:

#include <stdio.h>
#include <stdlib.h>
#define MAX 100
int fib(int n) {
static int memorize[MAX] = {1,1};
if(memorize[n])
return memorize[n];

[Code] ....

My main problem is that I have no visual of the current function, as well as the fact that it takes the f(n+3) = f(n+2) + f(n+1) + f(n), whilist I've only got f(n) to begin with.

View 5 Replies View Related

C++ :: Function That Should Return Number Of Digits In Integer Returns Last Digit

Feb 18, 2015

Code:
int exploder(int number,int array[]) {
int functi = 0;
int digit = number % 10;
while (number > 0) {

[Code] ....

View 2 Replies View Related

C++ :: Recursive Function - Take Number And Return With All Sevens Turned Into Eights

Apr 16, 2013

Task: Write a recursive function `seven_up` which takes a number and returns that number with all the sevens turned into eights.

- Example

cout<<seven_up(777)<<endl; //prints 888
cout<<seven_up(1234567890)<<endl; //prints 1234568890
cout<<seven_up(50)<<endl; //prints 50

- Hint: It's like removeFirst, except:

0. Base Case: If the number is one digit long, we don't want to erase it (by returning 0). Instead, riddle me this: When I have a one-digit number, what happens if I change all the 7's into 8's? Well, if the number is 7, it becomes 8, but otherwise it's unchanged.

1. Recursive Call: If the number is longer, then we strip off the last digit, figure out what the answer for the rest is (the recursive call on n/10), and then put the last digit back on the number when you're done.

Hint: You probably need to store the least digit (the n%10) and check if it's 7 separately.

#include <iostream>
using namespace std;
int removeFirst(int n) {
if(n<10)
return 0;
return 10*removeFirst(n/10)+n%10;

[Code] ......

I tried other algorithms but i don't get it.

View 14 Replies View Related

C :: Multiply One Array By Another

Dec 1, 2014

I am trying to multiply one array by another, for example:

enter 5 letters
enter 5 numbers,2 3 4 2
output= qq, www, tttt, ee

but im stuck with the last calculation.

Code:

#include <stdio.h>
#include <stdlib.h>
int main() {
char array1 [5];
int i, j;
int array2[5];

[code]....

View 1 Replies View Related

C++ :: Getting Bits In RDX After Multiply (x64)

Aug 13, 2013

Using the old fashioned (unsigned) multiplication instruction in x64 assembly multiplies RAX (64 bit register) by a 64 bit register. The answer is stored in RDX:RAX (i.e. the answer is 128 bits). Is there any way, using native c++ to get the value in RDX (higher 64 bits)? One I can think of is: right/(limit/left) e.g. if we are limited to a byte then 97*123 would overflow:

97/(255/123) = 46 times, which is RDX's (if it was one byte) value. But this is too inefficient. Is there a fast way?

View 4 Replies View Related

C/C++ :: How To Multiply Two Matrices Together

Mar 7, 2014

I haven't found anything that small for Matrix multiplication i was just going to ask about how i would multiply to matrices together in c++ as easy as possible, so for example say a i have the following

[2 0 1 0 * [3 0
6 -1 0 2] 0 3
1 2
3 1]

How would i multiply these together. Here is the example

Attached image(s)

View 11 Replies View Related

C :: How To Divide / Multiply Two Variables

Feb 26, 2013

I am new to C programming and I am just wondering how to multiply / divide two different variables which the user type in as the promt is asking like this:

Code:
void inmatning3 (double *a, double *b) {
printf("Mata in tv217 stycken flyttal: "); /* asks you to type in 2 numbers */
scanf("%lf %lf", a, b);
}

When you've enterd the two numbers I need to eather multiply or divide the two variables "a" & "b" .....

View 5 Replies View Related

C++ :: Multiply Values In Array

Jan 27, 2015

If we have array like

int numbers [] = {3,4,8,9,6,3,2,58,6,3,2,5};

how can we fast do smth like 3*4*8*9*6*3*2*58*6*3*2*5

also numbers[0]*numbers[1]*numbers[2] etc

all must be in one loop....

View 3 Replies View Related

C++ :: Multiply Two Dynamic Arrays

Mar 28, 2014

By using operator overloads i need to be able to * two dynamic arrays;

this is what i have so far

MyInt operator* (const MyInt& x, const MyInt& y) {
MyInt Temp;
int carry = 0;
if(x.currentSize > y.currentSize){
for( int i =0; i < y.currentSize; i++)
for(int j = 0; j < x.currentSize; j++)

[Code] ....

View 7 Replies View Related

C :: How To Correctly Multiply With Negative Numbers

Jul 24, 2013

I've been working on this program to create a simple desk calculator for a school assignment, and I managed to finish. All we had to do was add, subtract, multiply, and divide positive integers - and I was able to do that just fine. This program got me thinking though, because I do not know how to write commands to multiply/divide negative numbers.

In fact, when I divide a number like 21 by 4, it comes out to 5 because I don't know how to allow it to compute remainders (which wasn't a requirement for my program). This intrigued me so I've been trying to figure it out for the last few days but to no avail. Here's my code:

Code: void flush_buffer(){
int ch;
while ((ch = getchar()) != '
' && ch != EOF);

[Code]....

And just know that my code works perfectly fine, I'm not here for troubleshooting it. I just want to know what I can change to allow negative values to be correctly computed.

View 12 Replies View Related

C/C++ :: Multiply 2 Variables That Go From 0 To 7 - Logical Operators?

Apr 9, 2015

#include <iostream>
using namespace std;
int main(){
int polje[8][8];{
for(int i=0;i<8;i++)
for(int j=0;j<8;j++) {

[Code] .....

I don't get any errors,the program works. The problem is that it doesnt work how it should. This is a simple program that multiplies 2 variables(i and j)that go from 0 to 7. The problem I have is with the logical operators,i want the program to skip multiplication with 0 and when the 2 variables are the same value. When i try using only 1 logical operator it work.

View 2 Replies View Related

C/C++ :: How To Multiply And Divide 2 Numeric String

Mar 28, 2014

I want to multiply and divide 2 string that contains number. For example

s1=4 and s2=8 s1*s2=32 ,s2/s1=2

I don't want convert string to integer and do it.because i deal with big numbers.and these should be in string form.

View 1 Replies View Related







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