C :: If Statement With Multiple Conditions

Feb 26, 2013

I have tried writing a code and come across an issue where I'm not getting the desired result. It is to design a program that tells whether gas emissions from a car are too high, or permissible. The instructions are to design a code where there are four possible choices of pollutant, whether the emitted pollutant ratio is greater or less then a certain value, and the mileage on the car. All of these are supposed to determine whether the emissions are permissible or not, which would be displayed with printf. (The actual conditions of the assignment are described perfectly by the code below, so I didn't think it would be necessary to write it out. The problem is that I'm getting a logical error.) Here's the code:

Code:
#include <stdio.h>
int main() {
int poln, odr;
double gpm;
printf ("(1) Carbon Monoxide

[Code] ....

My error is that the program will proceed with the first four if/else statements, but once the 'poln' value changes to something other then one, it will not display the expected quotation.

View 3 Replies


ADVERTISEMENT

C++ :: If Else Statement To Check Multiple Model Numbers

May 2, 2013

I need to create a if else statement to check multiple model numbers (200+)... How can i build this? I basically want the user to enter their model number and if its on the list they get a approved or denied message.

So far I have this, the "if(model == 9002||1002)" doesnt seem right, it needs to basically check 200+ model numbers... am I even on the right track?

Code:
#include <iostream>
using namespace std;
int main(){
int model;
cout << "Enter model" << endl;

[Code] .....

View 3 Replies View Related

C++ :: Testing Conditions For Consistency

Dec 1, 2013

In the below program, when we have 4 consecutive spaces, the following comparison will not be equal: (x / tabstop != (x + spaces) / tabstop). If we have, let's say, only 2 consecutive spaces, then the comparison will be equal. So we know to print a tab with 4 consecutive spaces and not print a tab otherwise. How do we know this kind of division comparison would work in every case?

#include <stdio.h>
#define TABSTOP 4
int main(void) {
size_t spaces = 0;
int ch;
size_t x = 0; /* position in the line */
size_t tabstop = TABSTOP; /* get this from the command-line

[Code] .....

View 3 Replies View Related

C++ :: Best Way To Prompt User Again After Some Conditions Have Met

Mar 9, 2013

Here is a simple drinks machine programm. It basically consists in the user selecting a drink that it's presented, if the user selects correctly the number representing a certain drink, the machine shows the user what was the drink he selected, after his choise the machine asks for money insertion, if the user inserts the incorrect amount of money, the machine shows an error saying that user need to insert the correct amount of money.

My problem is that, if the user selects a different number other than those presentend, the machine displays an error saying that he needs to choose a valid drink, but i can't find a way to reprompt the user again after the error has been displayed. here's the code.

// ***Drinkins Machine*** by Roxmate
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
// initializes the variables coca, fanta, iced and drink to be used in switch function,so that the user can choose what drink he wants.
int coca = 1;

[code]....

View 5 Replies View Related

C++ ::  ascending Integer Conditions Not Always Met

Dec 4, 2013

I wrote a code to ascend any three integers. Problem is the code does not output the numbers in ascending order all the time. What am I doing wrong? here is my code :

// This program will prompt user to enter any three integers and then out integers in ascending order
#include <iostream>
#include <cmath>
using namespace std;
int main() {
int num1,num2,num3;
cout << "Enter the first number: " << endl;

[code]....

View 2 Replies View Related

C :: Do While Loop Fails When More Conditions Are Added

Mar 29, 2014

I'm trying to write a piece of code that calculates the difference in days between two manually input dates. The part of my code that's causing problems is:

xxx

When running the code and prompted to enter the date, if I input for example 31/12/2014, it'll be rejected and send me back to the beginning of the loop. Any date with 31 days involving months 1, 3, 5, 7, 8, 10 or 12 causes this problem. All other valid dates however work perfectly fine (e.g. 30/4/2014).

Something possibly worth mentioning is that, when I take out all other conditions from the loop, i.e.

xxx

it works fine (31/12/2014 is accepted), but of course I need all of the other conditions in there too.

View 1 Replies View Related

C++ :: Using Enumerations Types In Loops And Conditions - Ignored In Program

Jan 22, 2014

I am trying to use enumeration types in my conditions to make a simple program that calculates area of a square or circle depending on users choice then updates the total area and outputs the total area.

The program builds fine. But it ignores all of my loop conditions and i'm not sure why.

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

[Code] ....

View 4 Replies View Related

C# :: Switch To End Or Start Of Array Depending On Conditions?

Apr 1, 2015

I have a seat allocation algorithm for an airplane 30 x 6 seats. The plane is 'split' front (1 - 15) and back (16 -30), right (A,B,C) and left (D,E,F). I am placing passengers in window seats front right centre (15A) first then back left centre (16F) followed by (15F) followed by (16A). This will continue for single passengers middle seats then aisle.

Another part of the algorithm is to ensure parties >2 or <=6 to sit together in an empty row, if not possible the party will be split as to not have a person in the party sitting alone firstly. i.e. 6 is 3 + 3 or 2 + 2 + 2 or 4 + 2 or 3 + 2 + 1 or 4 + 1 + 1 or 3 + 1 + 1 + 1 and so.

I have got it working for one person but seating two people is a bit more difficult. I am trying to get 15A,15B then 16E,16F then 16A,16B then 15E,15F then 16C 16D and 15C 15D.

This code only allocates passengers 15 A 15B then 15C 15D then 15E 15F

//seat allocation for two people
public bool[,] seatTwoPerson(bool[,] seatArray, int startCol, int endCol, int directionX, int startRow, int endRow, int directionY)
{ //loop through seatArray section determined by parameters
//for (int col = startCol; directionX < 0 ? col >= endCol : col < endCol; col += directionX)

[code].....

View 3 Replies View Related

C++ :: Glass Rod - Get Triangle Variable To Increase When Conditions Met

Jun 25, 2012

I'm working on a project, and can't seem to get the project to get the triangle variable to increase when the conditions are met. I need this number to be accurate so I can work out the probability.

Experiments that are either too expensive or too dangerous to perform are often simulated on a computer when the computer is able to provide a good representation of the experiment. Find out how to call the random-number generator (usually a function returning a floating point value in the range 0 to 1) for your C++ system. (Look up the functions rand and srand in the library cstdlib on the website cplusplus.com). Write a program that uses the random-number generator to simulate the dropping of glass rods that break into three pieces.

The purpose of the experiment is to estimate the probability that the lengths of the three pieces are such that they might form the sides of a triangle. For the purposes of this experiment, you may assume that the glass rod always breaks into three pieces. If you use the line segment 0 to 1 (on the real number line) as a mathematical model of the glass rod, a random-number generator (function) can be used to generate two numbers between 0 and 1 representing the coordinates of the breaks. The triangle inequality (the sum of the lengths of two sides of a triangle are always greater than the length of the third side) may be used to test the length of each piece against the lengths of the other two pieces.

To estimate the probability that the pieces of the rod form a triangle, you'll need to repeat the experiment many times and count the number of times a triangle can be formed from the pieces. The probability estimate is the number of successes divided by the total number of rods dropped. Your program should prompt the user for the number of rods to drop and allow the experiment to be repeated. Use a sentinel value of 21 to hale execution of the program.

Code:
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cfloat>
#include <iomanip>
#include <stdlib.h>
#include <time.h>
using namespace std;
float doBreak (float, float);
float doProbability (float, float);

[Code] ....

View 11 Replies View Related

C++ ::  String Subscript Out Of Range / For Loop Conditions All Look Good

Apr 4, 2014

Im having a problem with my sneaky hangman game I feel like im really close just getting an error I can't fix. When I run it, it says something like string subscript out of range when I goggled it. it says im searching past the bounds of what it should be or something.

Also a dictionary.txt file is needed to run the program

code: [URL]

#include <iostream>
#include <string>
#include <fstream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int guessesUsed = 0;
int wordlength;

[code]....

View 3 Replies View Related

Managed C++ And C++/CLI :: Opening Forms With Buttons From Form 1 (With Conditions)

Jun 12, 2014

I'm pretty much newbie in creating a successful GUI in C++. Although, i managed to create 4 buttons that should show a certain form. Lets say, Form1 is my main form, therefore - Button 1 will open Form2, and Button 2 will open Form3..... But the conditions is - If there is a form that is already open, clicking again on the Button that should open it, will Close it, but all the forms (form1,2,3,4,5) can be enabled together.

Also, a very important note is that whenever i close a form, in any way of closing it (Not the main form) It will "save" the changes i made (Such as ticking checkboxes and so..) and won't reopen it, it will just use "Visible" i guess ?

Notes :

If i use Form2 ^form2show = gcnew Form2;

and then Form2->Show();

I will be able to simply ATTACK the button and open Billions of form2 ^_^

Although, when i use Form2->ShowDialog();

It won't let me open the form3,4,5.

Which isn't so bad, but when i exit from the form2, it won't save my changes (Such as checkboxes..)

View 6 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++ :: Transfer If-else Statement Into Switch Statement?

Sep 7, 2013

How to make if else code below into SWITCH STATEMENT?

cout << "Enter the temperature: ";
cin >> temp;
cout << "Enter the pressure: ";
cin >> pressure;
cout <<endl;

[Code]....

View 6 Replies View Related

C# :: Multiple Desktop Display (Multiple Explorer Windows)

Jul 31, 2014

I want to develop an application which can host multiple views of explorer (window), where as each window is totally separate from others. So that I can have multiple desktop views through my single explorer. Any built in feature in .NET ?

View 11 Replies View Related

C/C++ :: How To Make Multiple Subroutine And Return Multiple Arrays

Aug 17, 2014

how to make subroutines and return multiple arrays.Before that, i wrote my program on matlab. could my program to be structured as following?

<header>
initial value of program;
subroutine1() {
calculating the first work;
return 2 or 3 arrays;

[code].....

View 14 Replies View Related

C :: Redirecting Multiple Pipes With Multiple Children

Mar 21, 2014

I've been working on a function that works like a pipeline of a shell but receives a directory, go over it an search for every file to send it to a filter, something like this in bash "cat dir/* | cmd_1 | cmd_2 | ... | cmd_N", The only problem i have with the code is the redirection of the pipe descriptors.

Code:

int main(int argc, char* argv[]){
char** cmd;
int Number_cmd;
cmd = &(argv[2]); /*list of cmds*/
Number_cmd = argc-2; /*number of cmds*/
}

[code]....

The code is seems to work fine except when i run it with more than one command in example ("./filter DIR wc rev") in this case it returns

wc: standard input: Bad file descriptor
wc: -: Bad file descriptor
0 0 0

View 2 Replies View Related

C++ ::  Multiple Files Causes (Multiple Definition) Error?

Jul 15, 2013

I'm using multiple C++ files in one project for the first time. Both have need to include a protected (#ifndef) header file. However, when I do that, I get a multiple definition error.

From what I found from research, adding the word inline before the function fixes the error. Is this the right way to do this, and why does it work? Should I make a habbit of just declaring any function that might be used in two .cpp files as inline?

View 5 Replies View Related

C++ :: Take Max Of Multiple Elements In Multiple Vectors?

Mar 1, 2012

Say I have 5 vectors of unsigned char each of size 5. I want to take the max of each index and store it in a new vector. What is the most optimal way to accomplish this?

My slow code:

Code:
vector<unsigned char> vec1;
vector<unsigned char> vec2;
vector<unsigned char> vec3;
vector<unsigned char> vec4;

[Code]....

View 3 Replies View Related

C++ :: While Statement Is Never Ending

Sep 22, 2013

This while statement is not cooperating and I am not really sure why. I tried to say while not equal to true and later false, but both produce a never ending loop. I know I posted this before and I got several comments back about different issues with this program. However this question is specific about the while statement.

Code:
#include <iostream>
#include <vector>
#include <string>

using namespace std;

[Code] ....

View 5 Replies View Related

C :: How If Statement Works

Apr 30, 2013

I'm having a really dumb moment and I cant seem to remember how an if statement works, with only the variable name as the condition..

Code:
if(var){
//then do something
}

View 7 Replies View Related

C :: If Statement Not Working

Oct 21, 2013

Well for some reason this doesn't work.

Code:

#include <stdio.h>#include <ctype.h>
int main(void)
{
int lottoNums[150];
int num;

[Code]....

View 13 Replies View Related

C :: If Statement For Array?

Nov 17, 2013

how would i got about making an if statement for an array so it prints what u enter

Code:
example:
struct input{
float peopleseen;
float creditrate;
char insurprov[12];

[Code] ....

View 1 Replies View Related

C :: Using Scanf In If / Else Statement

Aug 7, 2013

When I do this:

Code:

#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] .....

But when I do this:

Code:
#include <stdio.h>
#include <stdlib.h>
int main () {
int guess ;
int number = 5 ;

[Code] ....

Why does the compiler say that there is an else without a previous if ??? ... Does this mean that I cannot use "scanf" in an if/else statement?

View 2 Replies View Related

C++ :: From If Else To Switch Statement

Mar 6, 2013

I was wondering how you would put this if else statement to a switch statement.

void PlayerDB::AddPlayer(const Player& avatarPlayer) {
char * playerName = new char[avatarPlayer.lenName()];
Player*player = NULL;

[Code] ....

View 1 Replies View Related

C++ ::  if Statement Always False

Jun 26, 2013

i am trying to make a ticktacktoe game. I made a simple one with no ai but i decide to add an option to play against computer. And i code like that(i know this is really bad):

/*
Name: TickTackToeFinal
Copyright:
Author:
Date: 26.06.13 20:41
Description:
*/
#include <iostream>
#include <string>

[code].....

when i run the game its always play randomly(last if statements in bilgisayar functions.

not:bilgisayar means computer
zor means hard
orta means medium
kolay means easy
oyuncu means player
tur means round
oyun means game

View 7 Replies View Related

C++ ::  If Statement In For Loop

Oct 5, 2013

I seem to be having a bit of problem with my if statements in a for loop.

My code involves asking the user for the name of an element (chemistry), searching a text file line by line for an element that matches the input, and outputting other information regarding that element.

One line of the text file looks like this: Helium,He,2,4.00

I've tried running the code without the if loop and it outputs normally (If I ask it to output elementname[0] it will output the first element Hydrogen, which is correct.) but I am not sure what goes wrong when I add the if statement. For some reason, it always follows the "else" statement (It always outputs Invalid search even when I input the right elements).

const int ELEMENTS = 118; //number of elements
ifstream File;
string elementname[ELEMENTS], atomicsymbol[ELEMENTS], atomicnumber[ELEMENTS], atomicmass[ELEMENTS];
string elemname, atomsym, atomnum, atommass;
string search;

[Code] ....

View 2 Replies View Related







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