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


ADVERTISEMENT

C :: If Statement Won't Check The Second Condition?

Sep 24, 2013

I've tried retyping the code several times and didn't work for some reason the If wont accept both Q and q it just accepts Q.

Code:
#include <stdio.h>
int main(void)
{
printf("A menu will show up and you choose the number for the selection you want.

[Code].....

View 9 Replies View Related

C/C++ :: If Statement To Check Matching Word To Pointer Address Value

Jan 3, 2015

I'm having an issue coming up with an if() statement to check if a word match the one in the value of a pointer's address. So far the best I've come up with only matches the first letter of the words, you'll find it in the code below.

#include"Header.h"
int Colour(struct MyStruct *ArrayPointer, int ArraySize) //ArraySize = 3 for this run. {
int ColourCount = 0;
for (int i = 0; i < ArraySize; i++) {

[Code] ....

An example run you can see in attached pic.

I want to have an if statement that only accepts "Red" and not the occasional "Ravaged_Anus".

I'm using MVS Express 2013, .c source files, and the C++ compiler.

Attached image(s)

View 3 Replies View Related

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 View Related

C :: Check Random Numbers To Appear Once Or Twice Only In Each Row Or Column

Oct 25, 2013

Code:

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <math.h>
int main()
#define rows 9
#define columns 9

[code]....

View 9 Replies View Related

C++ :: Model A Triangle With Three Vertices

Dec 27, 2013

Write a class called MyTriangle, which models a triangle with 3 vertices, is designed as follows. It contains:

1. The MyTriangle class uses three MyPoint instances as the three vertices.

2. Three private instance variables v1, v2, v3 (instances of MyPoint), for the three vertices.

3. A constructor that constructs a MyTriangle with three points v1=(x1, y1), v2=(x2, y2), v3=(x3, y3).

4. An overloaded constructor that constructs MyTriangle given three instances of MyPoint.

5. A toString() function that returns a string description of the instance in the format "Triangle @ (x1, y1), (x2, y2), (x3, y3)".

6. A getPerimeter() function that returns the length of the perimeter in double. You should use the distance() method of MyPoint to compute the perimeter.

7. Also write a test program (called main.cpp) to test all the functions defined in the class (example of a triangle: (-2, 1), (1, 3) and (3, -3)).

class MyTriangle {
MyPoint v1;
MyPoint v2;
MyPoint v3;

public:
MyTriangle(int x1,int y1,int x2,int y2,int x3,int y3) {

[Code] .....

View 3 Replies View Related

C :: Check How Many Times Numbers In Array Are Listed

Dec 24, 2013

How can I check how many times the numbers in the array are listed?

View 2 Replies View Related

C++ :: Print Numbers At Random From A Set Using Single Statement

Jan 21, 2012

I have an exercise that asks me to print numbers at random from the following set (using only a single statement):

2, 4, 6, 8, 10

Here's my statement:

Code:
cout << (2 + rand() % 9) << " ";

which prints numbers at random between 2 and 10, now I can use the modulus operator in an if...else statement to print only even numbers but the exercise specifically requires using only one statement, can that be done using the conditional operator? and if not then how?

View 10 Replies View Related

C++ :: How To Error Check If User Input Is Letters And Not Numbers

Jun 9, 2014

How do I error check if the user is inputting letters and not numbers? For example, if the user inputs "Lab.txt" I need to display an error message. If they input "Lab2part2.txt" then this is correct and what I want.

I've found a lot of information online on how to error check for numbers or a single letter (EX: 1,2,3, etc. or 'A' 'B' 'C') but nothing for actual WORDS or maybe I should refer to it as a string of characters?

Is there any way to do this? Because my program requires I ask the user to input the name of the file. But the way my code is currently set up is even when the user inputs the wrong file name it still opens the file. I want to prevent this from happening so my thought was to error check user input.

/*Program to determine company's weekly payroll*/

#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void OpenTheFile() {
ifstream inputFile;
string filename;
char letter;
int number;

[Code] .....

View 1 Replies View Related

C/C++ :: How To Put Together A Basic Ray Tracer Which Can Model Spheres And Planes

Dec 9, 2014

how to put together a basic ray tracer which can model spheres and planes. I have an example ray tracer which I am currently pulling apart and sifting through line by line to try and understand exactly how it works. I have come to a point in the code which I am having trouble explaining adequately. It's a method of the Plane class, which is a class defining the planes in the scene. The method is called findIntersection and I believe its purpose is to return the distance between the origin of the ray and the point of intersection, it looks like this

double findIntersection(Ray ray){
Vector ray_direction=ray.getDirection();
double a = ray_direction.DotProduct(normal);
if(a==0){
return -1;
}
else{
double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse()));
return -1*b/a;
}
}

The method accepts arguments of type Ray which is a class defining rays, rays are constructed from this class by supplying two vectors, a starting vector and a direction vector, the Ray class has a method function getDirection which is used in the first line of the findIntersection function which clearly just returns the direction vector. The DotProduct method being accessed belongs to the Vector class and is a standard method for finding the dot product of two vectors. "normal" is a variable of type Vector and is used in the construction of an instance of the Plane class, along with a distance from the centre of the scene and a colour. Also, in the line double b=normal.DotProduct(ray.getStart()+((normal*distance).Inverse())); the plus sign between the two vectors is an overloaded operator which adds the two vectors in the usual mathematical way, I overloaded it for neatness.

The trouble I'm having is working out what the variables a and b are doing, what they mean geometrically and how they correspond to getting the distance between ray origin and point of intersection. Clearly if the dot product of the normal with the ray equals zero then the ray is parallel to the plane and so there is no intersection but what is a's role in the return statement.

View 3 Replies View Related

C/C++ :: Check Rational Or Irrational Numbers After Taking Square Root?

Aug 4, 2014

I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..

View 10 Replies View Related

C :: Dynamic Load 3D Model From A File Located In Web Server

Feb 2, 2013

I have done a test, I have edited with the WordPad in Windows on my Local Webserver a file banana.h which contains a list of float arrays in order to extract one array and create a text file named ObjVerts.txt I have done a lot of search in the Web in order to find a small piece of code that can read the text file and convert it to a float array GLfloat, but I did not find any. I have found a lot of piece of code that read the file and make a NSData but many of the code seem to not work. It seem that the last statement return nothing!

NSURL *myurl = [NSURL URLWithString:@"http://localhost/ObjVerts.txt"];
//NSString *mystring = [NSString stringWithContentsOfURL:myurl];
NSData *mydata = [NSData dataWithContentsOfURL:myurl];

View 1 Replies View Related

C/C++ :: Analyze Population Dynamics - Forest Fire Model

May 15, 2014

I'm trying to analyze Population Dynamics. I found some articles and read them but what kind of model i need to use. I tried Forest Fire model but i failed in modificating.

#include <stdio.h>
#include <stdlib.h>
#define MaxPopulation 10000
#define MaxChildren 10
#define maxAge 70
#define ranf() ((double) random()/(double)RAND_MAX)

View 7 Replies View Related

C :: Loop Statement To Print Numbers From 1 To 10 In Reverse Order Separated By Star

Apr 21, 2013

Write a for loop statement to print the numbers from 1 to 10 in reverse order separated by star :

10*9*8*7*6*5*4*3*2*1

i try to do it but it show me like this :

10*9*8*7*6*5*4*3*2*1*

how do i write to show me like the first one ?

View 10 Replies View Related

C++ :: Program To Model Operation Of Incoming Flights Computer Screen

Apr 14, 2013

The project is "Design and write a program to model the operation of incoming flights computer screen that is normally found at a typical small airport like Moshoeshoe I airport (if they do have one). The following provides the information that needs to be displayed about each flight:

• Airline - [string of maximum length 15] Name of the airline, eg. FlySAA
• Flight Number - [string of maximum length 5] eg. 04120
• Origin - [string of maximum length 25] Place where the flight originated from eg. Johannesburg
• Date/Time - [integers: Hour, Minute, Day, Month, Year] Arrival time of the flight
• Status - [string of maximum length 15] Whether the flight is "OnTime" or "Delayed"

View 4 Replies View Related

C/C++ :: Read In String With Multiple Words And Numbers?

Jul 23, 2014

I am trying to read user input for recipe ingredients which must include a ingredient name, and may include a quantity and a unit. Example: Stone ground flour 2 cups or Sugar 1 Tbsp or Milk. The problem I am having is that the string gets cut off after a space when multiple words are used for the ingredient name.

cin.ignore();
string line;
getline(cin, line);
istringstream record(line);
string name;
string name2;
int quantity = 0;
string unit;
record>>name>>quantity>>unit;

View 1 Replies View Related

C/C++ :: User Input Validation - Finding GCD And LCM Of Multiple Numbers

Oct 23, 2014

I need validation on what the user inputs. Input should not be an alphabet, empty, and not negative number. This program is for finding the GCD and LCM of multiple numbers.

#include <stdio.h>
void bubble_sort(int numbers[], int len) {
int i, j;
int swapped;

[Code] .....

View 2 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++ :: Looping - Input Numbers Until User Types 0 Then Output Product Of Non Zero Numbers

May 1, 2014

How to do the problem below using loop?

Input numbers until the user types a 0, then output the product of the non 0 numbers: e

E.g., if the user types 2 4 6 0, the program should output 48

View 3 Replies View Related

C :: Finding Written Numbers In A String And Converting Them To Decimal Numbers

Jun 20, 2013

User enters sentence "The Smiths have two daughters, three sons, two cats and one dog." (The numbers may change depending on what the user chooses to enter. He told us the range would be from zero to nine.) and we have to convert the written numbers within the sentence into actual decimal numbers and print out the new sentence. Ex. The Smiths have 2 daughters, 3 sons...etc.

I have written the following bit of code which reads the string and finds all the "written numbers" but I am not sure how to proceed from there. I am stuck on how to print out the new sentence with the converted numbers as my professor mentioned something about creating the new string using dynamic memory allocation.

Code:
#include <stdio.h>#include <string.h>
int main () {
char A[100];
int length = 0;
int i;

[Code] .....

View 7 Replies View Related

C++ :: Find Prime Numbers Between Given Pair Of Numbers And Store Them Into Array?

Apr 18, 2014

Find all the prime numbers between a given pair of numbers. Numbers should be read in from an input file called "numbers.txt" and find all the prime numbers between them. Store the prime numbers in an array, then sort the array from greatest to least. Display the array before and after the sort.

I'm stuck on how to put the prime numbers into an array.

The input file has the numbers 1 & 100.

Here's what I have so far.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream fin;
fin.open("numbers.txt");

[Code] .....

View 1 Replies View Related







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