C++ :: Skipping Cin Statement

Sep 24, 2013

I have written a C++ program in which a user need to input a character. My problem is it's working fine for the first time but as it goes through the code second time, it skips the cin statement and takes the previous defined value. how can i make cin statement work for the second time also?

View 5 Replies


ADVERTISEMENT

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++ :: Getline Skipping First Time

Apr 25, 2014

why does this happen that if i use

string ans;
for(int i=1; i<3; i++)
{
cout << "enter an option" << endl;
getline(cin,ans)
}

in a loop it always skips the first time but in the next times it asks?

View 3 Replies View Related

C++ :: Getline Skipping First Line?

Aug 21, 2014

text file is

hello
there

void readFile(char[], ifstream&);
address records[numbersAdd];
int main(){
char xml[30];
cout<<"Enter file name ";

[code].....

View 6 Replies View Related

C++ :: Function Call Is Skipping

Sep 13, 2013

When I call the member function in the main function, two functions are working fine but the third one(print()) is not. The program stops after executing the read_ages function and nothing printed on the screen. This is really strange and I could not find any problem after spending hours and had to post it here.It is a very simple program but I cant find the bug. It is a multiple file program and I am using MinGW as a compiler.

//File 1

#include<vector>
#include<string>
class Name_pairs {
private:
std::vector<std::string>names;
std::vector<double> ages;

[Code] ...

//I haven't made the sort function yet since I am stuck with the print(). Seems //like the compiler is skipping the print() function.

View 3 Replies View Related

C++ :: Compiler Skipping User Prompts?

Mar 24, 2014

the problem that I'm running into is that the compiler skips to the end when I put my initials in //User input > "Initials"

I'm using Microsoft Visual C++ 2010 Express.

Here is the assignment:

Plan and code a program to do the following. You found an exciting summer job for 5 weeks. It pays $15.50 per hour. You will input the number of hours per week that you worked and then compute your total earnings. You must pay taxes of 14%. After paying taxes, you will spend 20% of your money on cloths and 5% on school supplies. After buying clothes and supplies, you will use 25% of the remaining money for savings.

Input

Your 3 initials and the hours for each of the 5 weeks. Use the following numbers of hours for your first test 25, 30, 20, 23, 22.

Calculations

Gross pay is the rate of pay times the sum of all hours you worked. Use CONSTANTS for each of the following rates:

Tax rate 14% of the gross earnings
Clothing 20% of earnings after taxes
School supplies 5% of earnings after taxes
Savings 25% of earnings after taxes and expenses

Output:

Output your initials, total hours worked, gross earnings, taxes, net earnings after taxes, clothing expense, supplies expense, amount going to savings and amount left to spend. Output must be aligned to the right as shown with 2 decimals in all numbers. Sample output:

Initials ABC
Total Hours Worked 120.00
Gross Earnings 1860

Taxes paid 260.40
Net Earnings 1599.60

[code]....

Turn in:Be sure your output file contains user prompts and what was entered by the user. In addition to the results of your program processing. Run with above listed data.

Here is my code

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double Initials, TotalHours, GrossEarn, TaxesPaid;

[code]....

View 6 Replies View Related

C++ :: File Management - Skipping Certain Lines From Files

Mar 11, 2013

I am supposed to write a program that reads lines from files and see if the first character is an odd number, if so it will out put the remaining characters to output file, else itll seek to the beginning of the next line, this is what i came up with but its not working as it should, im not sure if its the version im using or the program I wrote, the commented part below was another algorithm I was trying to use.

#include<fstream>
#include<iostream>
using namespace std;
int main() {
char c;
int i =0;

[Code] ....

My text file was as follows:
input.txt
3Ali
4Sami
6Rashid
3Aya

output was unexpected , although some was relatively write but not as I wanted...

View 3 Replies View Related

C++ :: Skipping Pieces Of CSV File And Putting Into Array?

Apr 18, 2014

I am trying to put pieces of a csv file into an array, but i only want to put certain pieces of it. This is the information that i have

Player,Current Team, Age , Nat , Position ,From,To,Transfer fee
Gareth Bale, Real Madrid,24,Wales,RW,Tottenham,Real Madrid CF,91000000
Edinson Cavani,PSG,26,Uruguay,CF,SSC Napoli,PSG,64500000
Falcao, Monaco,27,Columbia,CF,Atlético Madrid,Monaco,60000000
Neymar, FC Barcelona,21,Brasil,LW,Santos,FC Barcelona,57100000
Mesut Özil, Arsenal,24,Germany,AM,Real Madrid ,Arsenal,50000000
James Rodríguez,Monaco, 21,Columbia,RW,FC Porto,Monaco,45000000

With this i want to skip the name and team but need age.

View 3 Replies View Related

C++ :: Convert Binary To Base10 - Array Initialization Skipping Straight To Int Main?

Mar 3, 2013

I am attempting to write a program that converts binary to base10, and vice versa.

But in the function for converting Base10 to Binary, just as it reaches the line of code

int* binary = new int [a];
it skips straight to the int main()

All I'm attempting to do with that line of code is initialize the variable "a" into the elements of the array "binary".

[URL] ....

View 5 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 :: Reading From A File And Skipping Lines To Find String In File

Nov 26, 2013

Program background: Ticket Sales Details You will sell tickets in advance and at the door. Prices for buying in advance and at the door will be given. Also, the total number of tickets sold in advance will be given. Each guest will have a unique number. If there are n tickets sold in advance, then these guests will be numbered 0 through n-1. As the event starts, requests to buy tickets at the door may be made and these guests will be numbered sequentially, starting at the lowest unassigned number. The maximum number of guests will be 1000. The first line of the file contains the following three values, separated by spaces: Cost of the presales tickets (in dollars), Cost of the tickets at the door (in dollars), and the number of presale tickets. The first two values will be positive real numbers to two decimal places and the last will be a positive integer.

The second line of the file will contain one positive integer representing the number of auction items followed by a positive real value to two decimal places (at most) representing the minimum bid increment, in dollars. The first value is guaranteed to be 1000 or less and the second will be in between 1 and 50, inclusive.

The third line of the file will contain all the prices of the auction items, in dollars, separated by spaces, in order. Thus, the first price is the price of item 0, the next price is the price of item 1, and so on. These values will be real numbers represented to up to 2 decimal places.

The fourth line of the file will contain the three following positive integers pertaining to the raffle: the number of raffle tickets available, the cost of a raffle ticket in dollars, and the number of raffle prizes. (It's strange to have raffle tickets that don't cost a whole number of dollars.)

The fifth line of the file will contain each of the values of the raffle items, in dollars, separated by spaces, in order. Thus, the first price is the price if item 0, the next price is the price of item 1, and so on. These values will be real numbers with upto 2 decimal places.

The sixth line of the file will contain ten positive integers representing the number of each of the drinks 0 through 9, in order, that are in stock.

The seventh line of the file will contain ten positive real numbers with upto 2 decimal places representing the price of each of the drinks 0 through 9, in order.

The eighth line of the file will contain a single positive integer, numEvents, representing the number of events that occur at the charity ball. These events are split into two groups: actions by guests at the ball and awards given (raffle, auction, person, totalrevenue). All of the actions precede all of the awards. You will produce exactly one line of output for each event described. Here are the formats of each event that could occur:

If a patron buys a ticket at the door, a command will be on a line by itself:

BUY TICKET k

where k is a positive integer indicating the number of tickets bought at the door. These guests will be numbered as previously mentioned. You are guaranteed that the total number of tickets bought, including presales, will not exceed 1000. This is what I have so far and I cannot figure out why it wont calculate the total revenue. I am not completely sure if it is even accessing the if statement in main.

Code:

#include <stdio.h> #include <stdlib.h>
#include <string.h>
#define N 1000

[Code].....

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

C# :: Using If Statement And Loops?

Nov 28, 2014

I just want to say that I just started learning the language and this is my very first shot at writing a simple program that is not "Hello World" So I recently learnt the basics of the if statement and how to loop in a console application, here's what it looks like:

namespace Testing_IF_Statement
{
class Program
{

[Code].....

And again, this is just what I wrote in a few minutes without putting any thought into it.

Questions:
1)I have heard that the way I'm looping by using the goto statement is considered quite ancient, why is this and how else could I loop the program?

2)I declared a as an integer and asked the user to type 1,2,3,4 to perform mathematical functions, but when I tried declaring a as a string and searching if a == "PLUS" etc it would throw an error. Is there any mistake in how I approached this?

3)I know this is a bit premature to ask, but instead of writing _________ in the console to separate the loop is there any professional way to add a separator?

4)In general how can I improve the code?

View 9 Replies View Related

C/C++ :: Use Characters In If Statement?

Oct 15, 2014

#include <stdio.h>
#include <math.h>
int main(void)
{

[Code]....

That's my code above and I'm getting an error saying that I'm "implicitly declaring library function 'strcmp' with type 'int(const char*, const chat*)". When i run this program and enter in Black for the first prompt, the program stops. I'm trying to make this program so that when I enter Black as the answer for the first prompt, the program will display the value 10.

View 1 Replies View Related

C++ :: If Statement Multiplication By Zero

Mar 28, 2013

I want to set an integer to zero when it easy equal to another integer, but it seems that the program for some reason won't set the integer to zero. Here is the example of that code:

#include <iostream>
using namespace std;
int main () {
int n = 2;
int r = 2;
if(n==r)
n++;
r*0;
cout << " n is " << n << endl;
cout << " r is " << r << endl;
}

What am I doing wrong, it should say that "n is 3" and "r is 0".

View 2 Replies View Related

C++ :: For Statement - Loop Will Not End

Apr 30, 2012

My break; isn't ending the for statement. User should only get 3 choices but they get to input more than 3.

int playGame() {
int count =0; int x = (rand()%10)+1; int y;
for(int i=0;i<3;i++) {
cout << "Guess the number 1-10: ";
cin >> y;
if (x==y)

[Code] ......

View 6 Replies View Related

C++ :: Case Statement Not Working?

Mar 6, 2015

I have this case statement that is not performing as expected. For some reason ASE_OK and ASE_NotPresent both print out. Why is this? ASE_OK is a return value of 0 while ASE_NotPresent is -1.

Code: // Try to create the buffers and store it
switch (theAsioDriver->createBuffers(info, numChannels, bufferSize, callbacksInfo)) {
case ASE_OK:
std::cout << "ASE_OK";
input->bufferSize = output->bufferSize = bufferSize; // Buffer size is stored in both input and output
case ASE_NotPresent:
std::cout << "ASE_NotPresent";
errorMessage = "Could not find input or output devices.";
return NO_DEVICES_FOUND;

[code]....

View 3 Replies View Related

C++ :: Getting Error Using Enum In If Statement?

Jan 19, 2014

I'm trying to make a simple C++ program in which the user must try to guess a number, if they guess too high it says "too high" and if they guess too low it says "too low".

I also decided to add a feature which allows them to select how many tries they would like to guess the number. I tried to make "tries" type an enum so if the user could not pick an invalid number but for some reason i cannot use it in an if statement.

here is the code and i am getting the first error on line 27:

Code:
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
int guess;

[Code]....

View 7 Replies View Related

C++ :: Switch Statement Is Not Working?

Aug 16, 2014

okay so like case 2 and 3 is not working, also the program is still not finish but why isn't case 2 and 3 not functioning well on the switch part? case 1 works just fine

Code:
#include<stdio.h>
main ()
{
//passcode part (passcode is 1234)

[Code].....

View 5 Replies View Related







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