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"
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)
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;
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
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.
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 {
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 ==>
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...
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);
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...
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;
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:
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:
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:
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?
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");
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.
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);
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 ....
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;
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.
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