C++ :: Correct Answer From File - Cin Getting Wrong User Input

May 31, 2014

So I'm writing a program that will read a text file and it will do certain "functions" the text file will be like a game, and the program will be able to run many different games. The problem i'm having is in one of the "functions" i believe it's the one meant to get a correct choice from a file and a user input and put them into strings, it gets the wrong input. I know this because i tested both strings the "function" writes too. it gets the correct file answer but the user input is always "c" for some reason.

#include "stdafx.h"
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <stdlib.h>
using namespace std;
int progfiles() {

[Code] ....

This is the code, most likely the section that is surrounded with "///" contains the problematic "functions." This is the command Line output...investigate why they're dieing or continue on your journey?(i-investigate/c-continue) got input and answer

i
c
i
Press any key to continue . . .

The got input and answer are tests to make sure it got both, the first 'i' is my input, the 'c' is what it says my input is, and the 'i' is the correct answer from the file. this is the part of the file that the program reads to get that output

"1 Do you want to go investigate why they're dieing or continue on your journey?(i-investigate/c-continue) 2 8 i 7 3 4 You continue on picking up speed to get to the egg first.. and.. Oh No, You accidentally bumped into the walls! 2 12 5 1 You go over, and as you realize the walls are acidic and that's why the other sperm are dieing.. 2 6"

View 3 Replies


ADVERTISEMENT

C++ :: Quiz Program - Checking Whether Entered Answer Is Correct From A File

Apr 15, 2014

My code is not moving past the line below...actually i am making a quiz and this piece of code id checking whether the entered answer is correct, from a file..

getline(anss,saveans);
while(a<1) {
getline(anss,saveans);
if (saveans == ToString(randNum)) {
getline(anss,saveans);
if (saveans == ans)

[Code] ....

View 9 Replies View Related

C++ :: Get Correct Answer For Every Value Of X / N And A

Jun 10, 2014

I am expecting to get correct answer for every value of x, n and a[i] where

-10^9 <= a[i] <= 10^9
1 <= x <= 10^18
and 1 <= n <= 10000

Every value here is an integer value

#include<cstdio>
#include<iostream>
#include<cmath>
#include <float.h>

#define sBig long long int

[Code] .....

View 1 Replies View Related

C++ :: Recursive Function - Prompt User To Input Base And Exponent Then Generate Final Answer

Oct 31, 2014

I am studying about recursion by myself and i want to make a recursive function that prompts the user to input the base and exponent and generate the final answer .

#include<iostream>
using namespace std;
int recursive(int x, int y);
int main() {
/*int total=1;
int y, x;

[Code] .....

View 4 Replies View Related

C++ :: Program Compiles Successfully But Calculations Give Wrong Answer

Feb 11, 2013

I'm using MSVC++ and it builds sucessfully but somewhere something is obviously messed it. Once i try to debug it just shows weird numbers.

int k=0; //could this be the problem??? since 0 would be over writing any given value. but if i leave int k; it showsa warning and MSVC would count that as an error

#include "stdafx.h" //Header file section
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
//structure declaration
struct menuitemtype

[Code] ......

View 14 Replies View Related

C :: Correct Answer Does Not End Game

Feb 21, 2013

Okay so I thought I had this assignment completed properly last week. Last night I found a bug while playing the game.why won't the game end when the player guesses the correct number? The game allows you to finish using the max number of guesses even though you already guessed the correct number.

Code:

#define _CRT_SECURE_NO_DEPRECATE
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#define MAXGUESSES 6
#define MAXGAMES 20
#define MAXNUMBER 100
}

[code]....

View 9 Replies View Related

C++ :: Math Tutor - Guess Correct Answer Of Random Numbers

Jul 11, 2014

Objective: Guess the correct answer of the random numbers

Problem: I guess the correct answer but the program keeps telling me that I'm INCORRECT.

#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(int argc, const char * argv[]) {
const int MIN_VALUE = 1; // Constants
const int MAX_VALUE = 200;

[Code] ....

View 2 Replies View Related

Visual C++ :: User Input In Two Arrays - Comparison Always Show Zero Correct Answers

Nov 3, 2012

The following program takes user input into two arrays and should then determine how many items are different by comparing them with a loop. The comparison always show zero correct answers.

#include <iostream>
using namespace std;
const int QUESTION = 20;
//class for testing grades
class TestGrader {

[Code] ....

View 4 Replies View Related

C++ :: Delete Invalid Input Until Correct Input Is Entered?

Mar 20, 2014

Program is to add two fractions together like so..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> 3
Enter numerator 2 ==> 1
Enter denominator 2 ==> 6
1 1 1
--- + --- = ---
3 6 2
-----------------------------------------------------
Continue? Y or N! ==> n

My question is that i need each input to be a number.
if a character is entered i want it to output something like..

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==> a
You need to enter a number here.
Press any key to continue.

and then clear the part where the letter was entered.

This program adds fractions. ‘Y’ continues, any other key exits program
===================================================
Enter numerator 1 ==> 1
Enter denominator 1 ==>

View 5 Replies View Related

C++ :: Check Wrong Input Data

Jan 20, 2013

i'm making a for loop for a mini game which required the user to enter the input number.Let say if the user accidently entered a character instead of integer the whole program will go haywire so is there anyway to check for the error and prompt the user to input the data again?Here is the simple program...

for(row=0;row<4;row++)
{
printf("Enter Row%d:",row);
for(col=0;col<4;col++)
{
scanf("%d",&num[row][col]);
}

View 1 Replies View Related

C++ :: Cin Input Validation Returns Wrong

Jul 11, 2014

I have this function that is supposed to take a float as a parameter and then call the getLine() method to accept the users input. The function basically just checks to see if what the user input was of the same data type, if it is it returns the input value, if not then it keeps looping through taking new input until its correct. The problem is no matter what number you put in the output always returns as 140734799803512.

float InputValidation(){
float num;
string strInput;
while (true){
getline(cin, strInput);

[Code] ....

You also need to include <string> and <sstream>.

View 3 Replies View Related

C :: Give Error Message If User Inputs Wrong

Nov 2, 2013

Code:

#include<stdio.h>
void main
{
int i;
int marks[10];
}

[code]....

how to give error and ask user to re enter if user enter other then a number?

View 6 Replies View Related

C :: If Put WRONG Input For INTEGER / Program Will Restart

Feb 15, 2015

I have a question about my program.. I would like to make a program that if you put "ABC" on INT, the program will restart again... below are my coding...but it not works..if i put ABC on INT, the "Invalid Mark.. please re-insert mark :" will repeat, repeat and repeat infinitely...

Code:

#include <stdio.h>
void calcul() {int mark;
char * grade;
if (!(scanf("%d",&mark))){printf("
}

[code]....

View 7 Replies View Related

C++ :: Temperature Conversion Is Coming Up Wrong When Enter In Input

Feb 1, 2015

How would you be able to show both outputs celsius and Fahrenheit and my temperature conversion is coming up wrong when i enter in the input. here is my code...

#include<iostream>
using namespace std;
int main(){
double celsius;
double fahrenheit;

[code].....

View 1 Replies View Related

C/C++ :: Output Is Not Correct - Squaring Input?

Feb 6, 2015

Ok so This is what the output of the program should be.

enter the count of input integers: 1
The count of the integers must be two or more. Please enter a valid number : 3
Enter integer #1 : 2
Enter integer #2 : -1
Enter integer #3:5

The positive numbers entered and their squares are:

2 4
5 25

My Code :

//header files
#include<stdio.h>
#include<ctype.h>
#include<string.h>
#include<math.h>

[Code].....

View 6 Replies View Related

C :: User Input To File

Mar 18, 2013

I'm creating a program that should create a structure of a list of people entered by the user; the only problem I'm having is with the %c. When I have it, the loop only occurs once; if I put a %s, the loop occurs up to 25 times, but it doesn't write to the text file. Here is the code:

Code:
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
[code]....

View 2 Replies View Related

C Sharp :: Input String Was Not In Correct Format

Apr 28, 2012

List<Byte> Pt_split(string plain)  {
            List<Byte> pb = new List<Byte>();
            // Byte p;
            string p;
            int temp = 0;
            if (plain.Length % 2 != 0)

[Code] ....

View 2 Replies View Related

C++ :: Fscanf And Verifying Correct Input Length

Jan 24, 2012

I am trying to make a program that will read in input in the following format:

| ...text... || ...more text... || ...still more text...|

i.e. every bit of "text" that gets read in is bracketed on either side by the "|" character.

The buffer that i read them into can be of a maximum length of 101 (100 characters plus a terminating null character); this is how I am currently reading in the input:

char readString [100 + 1];
while ( fscanf(infile, "|%1000[^|]|", readString) ){
/*... manipulate readString ...*/
}

How might I design this program so that, should any of the text appearing between the "|" characters exceed 100 in length, it exits and returns a warning?

View 4 Replies View Related

C :: Create File From User Input

Jun 27, 2013

I want to create three files whose names are same but extensions are different. I have to take the name from user. I tried following code but it didn't worked ...

Code:

printf("Name of the file:"); scanf("%s",name);
printf("Format of Input file:");
scanf("%s",ext);
f1=fopen(name.ext,"r");
f2=fopen(name.dat,"w");
f3=fopen(name.src,"w");
f4=fopen(name.RMH,"w");

View 1 Replies View Related

C++ :: Opening User Input File Name?

Jun 17, 2013

why this is looping in an error message. I am inputting the entire file name when I run the program and it just keeps falling into my "if(!inputfile)" statement. Let me know if there is anything I'm just not seeing.

#include "File.h"
#include <iostream>
#include <fstream>
#include <string>

[Code]....

View 3 Replies View Related

C :: Unable To Input Correct Form For Matrices Multiplication

Jan 8, 2015

I am unable to input the correct form for matrices multiplication. I have an exam tomorrow in which I need to use this.

Code:

#include <stdio.h>
#include <conio.h>
int main() {
float a[10][10], b[10][10], c[10][10];
int i, j, k, l, n=0, m=0, x=0, y=0, sum=0;
printf("Enter the number of rows and collumns of the first matrix");
scanf("%d %d", &n, &m);

[Code]...

View 7 Replies View Related

C++ :: How To Open File TXT That User Input In Ifstream

Sep 9, 2013

How to open a file that the user input

ifstream InFile;
ofstream OutFile;
InFile.open("???.txt")

View 3 Replies View Related

C/C++ :: Prompt User To Input File Name To Open

Aug 31, 2014

I'm trying to develop a programme which, amongst other things, prompts the user to enter the filename which is to be opened. This is what my code looks like currently:

char filename[20];
FILE *myfile;

printf("Enter the full file name you would like to open:");
scanf("%s", filename);

[Code] .....

However, this only ever returns File Not Found - the file is stored in the same directory as the program, and I have tried looking up this issue online, to no avail ....

View 2 Replies View Related

C :: Program That Allow User To Input String Then Scans The File

Sep 21, 2014

This program will allow the user to input string then scans the file if it contains the same string given by the user. But i always get "MATCHED" even if i enter random string. I tried and tried to place the if statement in different positions but i dont get my expected output.

Code:
#include<stdio.h>#include<stdlib.h>
#include<time.h>
#include<string.h>
int main() {
int found;

[Code] ....

View 6 Replies View Related

C++ :: Program Which Takes Input From User And Write It To A File

Jan 15, 2013

A program which takes input from user and write it to a file then it reads data from that file then it should search for specific data such as email adresses or url etc.

View 1 Replies View Related

C++ :: Display All The Contents Of A File Excluding One Based On User Input

Mar 10, 2014

i want to display all the contents of a file excluding one based on user input say i have 4 records in the file numbered 1 to 4....the user chooses 2 to exclude it outputs records 1,3,4,4 when it should be records 1,3,4 what am i doing wrong here is the code.its basically displaying the last record in the file twice

void excludeRecord()
{
ifstream read;
read.open("Data.txt");
int recordC =0;
string fnameC = " ";
string lnameC = " ";

[Code]...

View 2 Replies View Related







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