C++ :: How To Combine Inputs Using If Statements

Jul 19, 2013

How to combine the if statements?

cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}

[Code]...

View 13 Replies


ADVERTISEMENT

C++ :: String Inputs On If Statements

May 26, 2014

How to make an input with a string thats part of an if statement. How I think it should be done :

#include <iostream>
#include <string>
using namespace std;
int main() {
string choose;

[Code] .....

But I get a strange warning (not an error, but something that is like "just letting you know" i suppose) and when i enter in ss or SS or aa or AA, it breaks my app.

View 7 Replies View Related

C/C++ :: How To Find Highest And Lowest With 3 Inputs In Different Control Statements

Aug 10, 2014

We will make it in Turbo C, C++ and VB.. but as of now (Turbo C and C++)

This is the problem

Make a program based on the given logic below

a>b && a>c - a highest
b>a && b>c - b highest
c>a && c>b - c highest
and will determined the lowest

we will do this in different program control statements:

1.If-Then-Else
2.Multiple-If
3.Nested-If
4.Do Case
5.Do While
6.Do Until
7.For Next
8.Switch
9.Break
10.Loop

is it possible?

View 1 Replies View Related

C++ :: Combine RGB (A) Pixels Into One?

Jan 14, 2013

I have a buffer which has a virtual width of 1024 pixels with virtual height 768 pixels (actual width stored in GPU.GPU_screenxsize, height in GPU.GPU_screenysize (both uint_32)).

I currently use the following function to plot the pixels to the screen:

inline void GPU_defaultRenderer() //Default renderer {
uint_32 pixel;
int bufferx; //Buffer's x!
int buffery; //Buffer's y!
int bufferxstart; //Buffer's x start!
int bufferystart; //Buffer's y start!
int pspx;

[Code] ...

How to combine the pixels together (blend them into one goal pixel) to get a better view? (Currently it takes the bottom right pixel of the area that represents the goal pixel).

So (x1,y1,x2,y2)->(pspx,pspy) = (bufferystart,bufferxstart,buffery,bufferx)->(pspx,pspy).
Atm this is (x2,y2)->(pspx,pspy)

Btw the pixel format is uint_32 RGBA (only RGB used atm). The psp_graphics_putpixel draws it onto the real VRAM. PSP_SCREEN_ROWS and PSP_SCREEN_COLUMNS represent the destination screen (the real screen)'s height and width in pixels.

View 7 Replies View Related

C++ :: Combine Two Program Into One?

Jan 13, 2015

i tried to combine two programs into one.. in my first program it has one class object and main() and my second program it has only one main()

i want to combine these two into one

View 5 Replies View Related

C# :: How To Combine Two SQL Queries Into One

May 21, 2014

update Tag_Master set flag='Inactive' where Tag_no=10;

update Tag_Master set flag='Assigned' where Tag_no=12;

I had these two queries, I just want both of these will fire on same event. Is any other way to write both queries in single query instead of writing two different queries ....

View 4 Replies View Related

C++ ::  how To Combine A Function Call And Inputting A Value

Mar 15, 2014

We're working on classes in my programming class, and I have a question about function calls.

Bascially, I have all my set and get functions set up and ready to go.

I was wondering if it was possible to have the user input a variable while calling a function.

for example

cin >> getname();

the user inputs a value that gets passed into getname.

Or does it have to be something like

cin >> name;
getname(name);

mind you all, this isn't code from my program i'm just spitballing here.

View 4 Replies View Related

C# :: Combine Query To Show All Data

Sep 22, 2014

So I've been working on this for awhile and FINALLY got it to work. This is my code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;

[Code] ....

As you can see I will have the Name and total right next to eachother.. Problem is I dont want to make a million MySQLCommands for each ID.. Is there a Way I can list all data in each label?

For instance the Select from Text will show all the text from each different ID
and the Select from STOCK-USED as total will show all the total for each ID

Instead of having to list them individually.

Even if I leave it to this

"Select text FROM `parts`";

It selects the 2nd ID in my database and displays its text.. Forgets about the first one completely ...

View 2 Replies View Related

C# :: How To Combine Two Bytes In Int32 To Get Original Value

Jan 6, 2015

how to combine two bytes (each byte is 8 bits wide) in order to get the original value. I am displaying values(from 0 to 500)sent from my microcontroller on the GUI.I can successfully display values from 0 to 255 as this requires just sending a byte. However sending values from 256 to 500 requires sending two bytes. The problem I am having is that I was unable to re-combine the received two bytes in order to get the original value. Below are my lines of code:

int main( void ) // this is the main function inside the microcontroller {
sei();
USI_TWI_Master_Initialise();
Spi_Master_Init();
while(1) // I am using this loop to send 500(111110100) {
Transmitt_Receive(244);//this function sends LOW BYTE of 500(11110100)
_delay_ms(1000);

[code]....

When I combined the two bytes using the above arrangements, instead of getting 500 my GUI displayed 62708.I got the same result when I used BitConverter.

value3 = BitConverter.ToInt32(val,0);

View 7 Replies View Related

C# :: How To Combine 2 Methods To Make SQL Class

Jun 17, 2014

I am given 2 methods and they want me to create a stand alone class for sql that will change the sql string.

my question is how can i take these 2 methods and make one class out of them that will used on various other forms.

#1

public string AuthenticateWithDB(CUiPontisDatabaseSpecification pdb, string sUserId, string sPassword,
bool bCreatePersistentCookie)

#2

public static void ChangeConnection(Util.ODBC.ODBCDSN odbcInfo, CPonDatabaseVendorType dbType, string uid, string password)

they want it so they can use it like

CUiHttpSessionManager.SimpleDataConnectionString = SomeNewClass.CreateSimpleDataConnectionString()

where some new class is my new class

View 5 Replies View Related

C++ :: Combine Multiple Vector Containing Binary Data To String?

Mar 16, 2012

Two questions:

1. I have some vector<unsigned char> containing binary data. I would like to combine them into one std::string. How is the correct way to accomplish this?

This is my best guess for sample code:

Code:
vector<unsigned char> data; //conatins some data
vector<unsigned char> data2; //contains more data
string temp(data.begin(), data.end());
temp.append(data2.begin(), data2.end());

Will this code work with binary data, or will it null terminate?

2. A similar problem.. I have some unsigned char* variables, and I want to combine them into one std::string. How can I accomplish this? will the member append() work here? or will it null terminate? Something like:

Code:
unsigned char* data; //conatins some data
unsigned char* data2; //contains more data
string temp(reinterpret_cast<const char*>(data));
temp.append(string(reinterpret_cast<const char*>(data2)));

Will the above sample code work without null termination?

View 4 Replies View Related

C++ :: Record User Input But Combine It With Command Line Arguments?

Aug 15, 2013

I want to be able to write a program where I can record user input but combine it with command line arguments. For example I do a simple getline(); and the user types test how to combine it so it could be like test /q and it gives a different output depending on what additional input was added. Can this be done with lots of different inputs?

View 8 Replies View Related

C/C++ :: If Else Statements Being Ignored

Feb 7, 2015

My problem is that some of my conditions are not being triggered when the price level of a medium or large discount is smaller than the cost of the widget(defined as .40) An example being ,base price, $2 med discount 80%, and large discount 90%. My med discount is,1.6(80%) off of 2, so $.40, which is fine, but 90% off mean 1.8(90%) off of a base of $2, which is $.20 which is too low., and should trigger the 4th if statement, Nick you are discounting large purchases too much!. However when I run this in the program, I am triggering the first if statement.

#include <math.h>
#include <stdio.h>
#define widget_cost 0.40
int main (){
float sellprice;
float discount_med_price;

[Code] ....

View 2 Replies View Related

C :: Boolean Value Use For If And Else Statements

Apr 20, 2013

Am i using boolean values correctly? our professor wanted boolean value use for the if and else statements.

Code:
#include <stdio.h>
#include <math.h>
#define GRAVITY 9.8
#define LIMIT 500
#define SEC 5

[Code] ....

View 2 Replies View Related

C :: IF Statements Within Loops

Jan 29, 2014

I've just started learning the C language, and I'm stuck on something that is probably quite simple.how to get IF statements working within WHILE loops. My code is below. I am trying to write a program to count the number of words in a sentence, and obviously stop counting after a full stop has been entered. I created a variable called 'spaces' which will increase by one after the user enters a space. However, when the IF statement is in place, the loop never terminates, even if I enter a full stop. When I delete the IF statement, the loop functions correctly.

Code:

#include <stdio.h>
int main()
{
char x;
char a;
char y;
int spaces = 0;
}

[code]....

View 4 Replies View Related

C++ :: How To Use If Statements With Strings

Jul 3, 2013

I've got a very simple but annoying problem.

if (letter3=="
"){
letter3==letter;
PrintCharacterLineEnd();

This is a code. the string "letter3" contains the string "
". What I want to happen is when, letter3 contains the text "
" I want to go to the function PrintCharacterLineEnd.

However, as of right now it's not working.

View 14 Replies View Related

C/C++ :: Using Strings And If Statements?

May 3, 2012

The problem with this code is that there are no errors showing, but when i compile the program, the if else statements do not carry out as they should do. Both if statements show the same answer, for example the second if statement. If I type Y or N then I get the same thing, 'You will now choose an event'. How do i get rid of this problem? Is char supposed to be used or string?

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

[Code].....

View 1 Replies View Related

C :: For Loop Skipping Statements

Jan 26, 2013

im a newbie C user and im having a little trouble in these for loop of mine im using. the first iteration is all fine but on the second and succesive iterations the first gets statement is skipped. im making a program that would ask the user to input multiple informations for atleast 5 people. i was also asked to use structures.. here is the code i have come up so far.. ive been stuck in it for like 3 hours now.

Code:

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
}

[code]....

gets part for the line "Enter ID Number is skipped on the second iteration..

View 3 Replies View Related

C :: If Statements For Dice Rolling

Oct 9, 2014

I'm very new to C Programming and am doing some homework for my intro to C class. "There is a game where one can play and bet money on. Two dice are rolled and the numbers that appear on the dice are added together. If the total is 7 or 11, then the user wins. If the total is 2 or 12, then the user loses. If a different total appears. then the user gets their money back."

I have written the program below:

Code:

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
void main()
{
int d1,d2,sum;
d1=0;
d2=0;
}

[code]...

However, after finishing the program, I realized that I NEEDED to use random numbers!!! How do I make my program generate random numbers within a range of 1-12? Also, how do I make my program generate NEW random numbers EVERY TIME instead of ONCE??

View 1 Replies View Related

C :: Statements Within Braces Are Indented

Apr 25, 2013

When we say that the statements within the braces are indented, we mean a tab character distance? For example if we have :

Code:

// K&R Style
void some_function(void)
{
<1 tab>int x=1;
<1 tab>printf("Inside the function");
while(x<3) {
<1tab><1tab>printf("Inside the loop");
x++;
}
return;
}

That is right?

View 3 Replies View Related

C :: Operators In Switch Statements?

May 20, 2013

Switch case statements are a substitute for long if statements that compare a variable to several "integral" values ("integral" values are simply values that can be expressed as an integer, such as the value of a char).

So does that mean switch statements can only test if variable == value and nothing more, like > < >= <= != etc... ? I tried to make a program to test this and it seems like switch statements are limited to == but I'm not sure, maybe I'm doing something wrong.

This is the program I tried to make to test this:

Code:
#include <stdio.h>
int main () {
int n;

[Code]....

So is it true that switch statements only work with the built in == operator? if that was the case then I would feel rather meh about switch statements.

View 7 Replies View Related

C++ :: If And Else Statements With Game Scores

Oct 20, 2014

I am in comp. Sci 1 at my school and I have to write a program that deals with gamer scores and the trophy they get according to expert level. For example Tom is a beginner and gets a gold medal if >=10000 a silver >= 7500 bronze if >= 5000 and no trophy if he score <5000 ! I have do this scoring for Beginner, Immediate and Expert.

Should I set up the beginning like this:

case'b':
case 'B':
if (score >= 10000 )
trophy= gold
if (score >= 7500)
trophy = silver
if (score >= 5000)
trophy= bronze
else = none

Not really sure how to go about solving this problem

View 4 Replies View Related

C++ :: Switch Statements In GLUT

Jan 3, 2014

I'm making a game in OpenGL GLUT. A ball is going to move forwards along the Z axis and hit a wall. I want to be able to move the ball left and right, up and down before firing it off on the Z axis. I'm using glutSpecialKeys for this, and I've got everything set up, but I'm not sure how I use it with a switch statement? Here is a snippet of code:

void Special_Keys (int key, int x, int y){
switch(key){
case GLUT_KEY_UP: //do something
break;
case GLUT_KEY_DOWN: //do something

[Code] .....

Where the comment is saying "do something", I'm not sure what I actually need to do? Is it a method or what?

View 1 Replies View Related

C++ :: Randomizing Order Of If-else Statements

Dec 11, 2013

The purpose of doing this is so that the top of the if statements is not preferred over the bottom. I tried assigning enum values to each case. Then choose a random integer r from 0 to the size of the std::list myList containing those enum elements. The enum value is found using it = std::next (myList, r). Then if the if statement corresponding to that enum value is false, then myList.erase (it), and repeat the process with the newly reduce myList. It works, and everything seems nicely randomized. But it is disappointing much slower than when I used the original if-else statements (it is being applied hundreds of times).

Here is a snippet of my code (I decided not to use switch statements because it looked too clumsy):

std::list<FacingDirection> guyFacingDirections = {Positive_x, Negative_x, Positive_y, Negative_y, Positive_xPositive_y, Positive_xNegative_y, Negative_xPositive_y, Negative_xNegative_y};
while (true) {
const int r = rand() % guyFacingDirections.size();

[Code] .....

There is a crowd of girls. Each guy will choose a girl, and then choose a facing direction to dance with his chosen girl. But not all facing directions are possible if someone is standing at the spot he wants to stand at to get his desired facing direction. Without randomizing the if-else statements, most of the guys will end up facing the same direction, which I don't like.

View 18 Replies View Related

C++ :: Execute The Previous Statements After Else Statement?

Mar 10, 2013

I have a condition and I would like to instead change the condition so that it would execute the previous statements after else statement.

It seems hard to explain but I'll try my best to illustrate anyway

if (condition)
<statement1>
else
<statement2>

So I would like to change the condition so that

if (condition)
<statement2>
else
<statement1>
And the condition is
Code:
if(!lightStateAtNextLink || !bIsLightEnAtConnection && nLinkNext.IndexToAttachedNode() != pVeh->_.stAutopilot.m_dwNextNode || bIsLightEnAtConnection && nLinkNext.IndexToAttachedNode() == pVeh->_.stAutopilot.m_dwNextNode)

And I have changed that to this. Is this correct?

Code: if(lightStateAtNextLink && bIsLightEnAtConnection || nLinkNext.IndexToAttachedNode() == pVeh->_.stAutopilot.m_dwNextNode && !bIsLightEnAtConnection || nLinkNext.IndexToAttachedNode() != pVeh->_.stAutopilot.m_dwNextNode)

View 5 Replies View Related

C :: Breaking Out Of While Loop With Nested If Statements

Mar 14, 2014

Code:

while(x==1){
for (i=0;i<j;i++)
{if (word1[i] == word2[i])
{prefix[i]= word2[i];
counter++;}
else
x=2;}

Basically after the 3rd run of the for loop, it encounters a contradiction. I want it to exit right there and then. Instead it continues to run the for loop. What can I do?

View 4 Replies View Related







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