C :: Y / N Option To Continue - Compiler Does Not Read It As A Loop
Jul 30, 2013
I've been having problems with my loop that asks if the user wishes to continue or not. The required input should either be 'y' or 'Y', or 'n' or 'N'. Anything else should be counted as invalid, and repeat the prompt for input. The first few times I ran my program, the compiler does not read it as a loop. The next few times just won't work properly.
Here is the prompt:
Code:
void question() {
char option;
printf("
Do you want to continue? {Y|N) ");
scanf("%c", &option);
[Code] ......
As it is, it immediately runs the else option, but otherwise runs just fine. I suspect it could be because I have not specified a size for the option variable, but I try doing that, and the prompt relegates everything to the else.
(And also, here's the rest of the code. Basically, it just assigns a value to the letters of the word (a/A = 1, b/B = 2, etc.), adds these values, and determines if a word is prime or not based on the sum.)
Code:
#include <stdio.h>
#include <string.h>
#define size 30
int main() {
char letter, word[size], lower, upper, option;
int i, value, ans = 0, a, choice = 1;
[Code] .....
View 4 Replies
ADVERTISEMENT
Feb 9, 2014
I was wondering how I could use a continue statement that continues in a nested loop. For example if I have
for (int i=0;i<amount;i++) {
for (int j=0;j<I[i];j++) {
for (int k=j+1;k<I[i];k++) {
if (P[i][j]+P[i][k]==C[i]) {
//What should be here?
}
}
}
}
If the condition is met then the most outer loop (in i) should continue to the next iteration.
If i simply fill in continue; in before the comment then it only continues the loop in k so that is not what I want.
View 5 Replies
View Related
Mar 17, 2015
what do I do if the while loop repeat iterating and do not stop running even if it did meet the conditions required?
View 3 Replies
View Related
May 5, 2014
I am working on a program that will do several mathematical calculation and will store the data into a csv file.The one below is just a prototype version of this.In my program,I will store my csv file as (current-date).csv using time.
With this in mind,I want my program to first check does (current-date).csv already exists.If not,the program runs normally and output all the data into the csv file.
However if (current-date).csv already exists,I want my program to read and edit that particular csv file,by skipping part1 in my code(name,id N etc.) and start with prompting the user for numbers straight-away.
In other words, if (current-date).csv already exists,the user should continue outputting the numbers from where the user last left before last termination instead of outputting the name,date & etc into the csv file again.
Eg: if no=22, continue inputting values from no=23 till terminating the program again and storing the values correctly into the csv file.
#include <iostream>
#include <fstream>
#include <iomanip>
#include <locale>
#include <string>
#include <sstream>
#include <time.h>
using namespace std;
// Program to read date N store it as currentdate.csv
[Code] ....
View 6 Replies
View Related
Feb 13, 2014
I need to reverse this loop. get how to do it in order but when i have to reverse it i get a compiler error
int main() {
cout << "Enter 3 cities" << endl;
string cities;
for ( int i = 0; i < 3; ++i ) {
getline(cin, cities[3];
[Code] ....
View 2 Replies
View Related
May 27, 2013
I just started on a project on c++ and I was wondering if it is possible to add a select option (where the c++ program requires the user to select an option) . I couldn't find this anywhere.
View 3 Replies
View Related
Mar 28, 2015
I already tried getchar(); but it doesn't worked the program skips this command
View 2 Replies
View Related
Oct 24, 2013
I am just now in my first programming class for learning C language and I am stuck on one of my homework assignments. I am not asking you to write the code for me or anything because I want to learn by doing it myself but all I am asking for is some pointers to where I am messing up. My program is already finished for what she asked for but I am trying to do an extra credit where she wants us to have the user decide how big the gameboard is and how many mines to hide in it. Really I know that I need to use srand() and rand() but I am not sure how to use them to randomly place mines and without placing mines on top of others.
Code:
//Program 3 "Minesweeper" by Casey Samuelson
//10-17-2013
//This program will imitate the game Minesweeper.
//Agorithum
[Code]....
View 4 Replies
View Related
Sep 9, 2012
I'm getting Unhandled exception when try to run option 3.
This my code below.
Code:
#include <iostream>
#include <string>
using namespace std;
struct Vet {
string name;
int numOfAnimals;
string phoneNum;
[code]....
View 8 Replies
View Related
Oct 30, 2013
My function is only reading the first line of numbers even though I have the loop to keep returning to it in main(). How do I have it read from the file until it runs out of data to retrieve?
File being read
90 83 94
72 65 81
File being sent the data(Only the second average is correct, working on the first)
Student Information
Student IDGradeAverageLetter Grade
1895612
90 83 94
289
90 83 94
#include <fstream>
#include <iostream>
using namespace std;
ifstream infile;
ofstream outfile;
void grades(int&,int&,int&); // Grades from the input file
int myavg(int,int,int); // Calculates the Average of the 3 grades
[Code] .....
View 8 Replies
View Related
Apr 20, 2015
My problem is , i want to make a simple calculator , in the console i want afterall the user to choose what type of operation he want pressing a key like i mentioned in the title the keys would be F1,F2,F3 , i'm not finding in the internet the code to the detection of a press key like what i want.
Code:
#include <iostream>
using namespace std;
int F1 (int x, int y) {
cout << "Enter a number: " << endl;
cin >> x;
[Code] ....
View 7 Replies
View Related
Mar 17, 2013
I am attempting to read a file with 2 numbers in it. The first indicates the number of rows the second, the number of columns. So for a file (Data.txt) that contains the numbers 5 7, I want to display
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0
1 1 1 1 1 1 1
0 0 0 0 0 0 0
and write that output to a file.I can display the correct number of rows and columns but I can't figure out how to display alternating rows of 0's and 1's.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ifstream inFile;//declare file
[code]....
View 5 Replies
View Related
Oct 30, 2014
I have this if block that is supposed to be creating a pipe then forking and I would like to combine the while loop below it with it. How would I do that?
p = pipe(pipe1);
if (p < 0) {
printf("pipe error");
exit(0);
} else {
printf("successful pipe1 = %d",p);
[Code].....
I have trying to read this documentation but don't understand it. [URL] ....
View 1 Replies
View Related
Mar 8, 2014
Basically we have to create a system for loan amortization for vehicle company. The code is still in its development stage and I am having problems with one of the menu selections. all the other menu selections work fine except for menu selection 3. I'm quite stuck on it. When I run the program everything goes well except when I enter 3 at the main menu, it just exits the program instead of going to the screen for the menu selection.
#include<stdio.h>
#include<conio.h>
#include<string.h>
main() {
char un, /*username*/
name, /*customer name*/
[Code] ....
View 1 Replies
View Related
Sep 18, 2012
i changed my code from release to debug mode. when i try to debug it shows a dialog box that '... does not contain debug information press ok to continue"..
View 8 Replies
View Related
Apr 20, 2014
The question is "Write a program that uses a while loop to read a set of integers from an input file called "data.txt" and prints the total number of even numbers read from the file."
Code below is the program I have created so far. I keep getting the window to pop up but not stay up so I am assuming I am doing something wrong.
#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::fstream input("data.txt");
if (!input.is_open()) {
std::cout << "There was an error opening data.txt";
[Code]...
View 5 Replies
View Related
Sep 3, 2013
I would like the coded ASCII image to scroll horizontally 3 times and then end with the message:
"Hit Enter to continue or Esc to end"
If Enter is pressed, the program should then continue to scroll another 3 times and then display the same message above.
If Esc is hit then the program loop should stop similar to an escape sequence.
Here is my code that partially accomplishes my objective:
Code:
// Professor.cpp : The entry point for the console application.
#include <iostream>
#include <string>
#include <windows.h>
#include <stdlib.h>
[Code] .....
View 3 Replies
View Related
Feb 13, 2014
I have a menu for a project that takes a string input and does whatever option you specify. It works perfectly EXCEPT when it goes through the while-loop (while you didn't say quit the menu reloads). It will spew out all the text in the menu like a bulimic teenager. Then it reloads properly and asks you for an input like nothing happened. While this is not a fatal error (code still functions)...
Code:
#include <stdio.h>
#include <math.h>
#include <string.h>
double aa=0, ab=0, ac=0, sa=0, sb=0, sc=0;
char a1[13], o1[]="AAS
[Code] .....
View 2 Replies
View Related
Jan 14, 2014
i need one more option which it can display all the items i have entered in alphabetic order in my program..this is my coding......
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define capacity 1000
void cal_item(struct item[capacity]);
void input(struct item[capacity]);
}
[code]....
View 1 Replies
View Related
Apr 1, 2014
So , i had to make an rock paper scissors game . After lot of hard work and struggle ,I completed it but my professor rejected it since I didnot add option where it says "Would you like to play again .Y/N " . The code has too many brackets ! Here is my code
#include <iostream>
#include <ctime>
#include <cstdlib>
using namespace std;
// for displaying the outputs to the user; passing string to functions
void user_win() {
[Code] ....
View 1 Replies
View Related
Nov 21, 2014
Remove the break statements from each of the cases. What is the effect on the execution of the program?
Add an additional switch statement that allows for a Passing option for a grade of D or better. Use the sample run given below to model your output.
Sample Run: What grade did you earn in Programming I ? A YOU PASSED! an A - excellent work!
Rewrite the program LastFirst_lab44.cpp using if and else if statements rather than a switch statement. Did you use a trailing else in your new version? If so, what did it correspond to in the original program with the switch statement?
// This program illustrates the use of the Switch statement.
// The break statement causes all subsequent expressions to be executed as well, also known as "falling through".
// The trailing else statement acts just like the default section if none of the options from before work it gets "defaulted" to it.
#include <iostream>
using namespace std;
int main() {
char grade;
cout << "What grade did you earn in Programming I ?" << endl;
[code]....
how do you add an additional switch statement? i tried multiple times and i'm not sure if i don't understand braces enough but it didnt seem doable. also, I'm not sure what the teacher wants me to submit.
View 1 Replies
View Related
May 6, 2014
I need to do a code that gave me Original string, uppercase string, lowercase string, reverse string (if letter is upper then convert to lower, and if lower then convert it to upper) and uppercase first (first character of each word in uppercase).
I need to do it in functions but i dont know hot to use strings. The program should provide the option to save the outputs in a file.
View 4 Replies
View Related
Nov 25, 2013
I need to promote user to enter y/n in switch statement to continue or not for an other conversion after showing results of each conversion.
#include <iostream>
using namespace std;
int main() {
char a;
double n, r1, r2;
cout<<"Please Chose the Temperature Unit to Convert: "<<endl<<endl;
[Code]....
View 1 Replies
View Related
Aug 10, 2014
So this is the activity (LOOPING) :
Write a program that accepts a positive integer. The program should be the same from the given output. Use do while to allow the user to continue or not.
OUTPUT must be:
n = 5
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
if n = 6
0
1==0
2==1==0
3==2==1==0
4==3==2==1==0
5==4==3==2==1==0
6==5==4==3==2==1==0
View 2 Replies
View Related
Apr 4, 2013
Code: Obj<TCHAR>* obj = dynamic_cast<Obj<TCHAR>* >(I->objects[0]);
Which is resulting in this error
Code: A dynamic cast is present, but the correct RTTI option is not specified.
View 3 Replies
View Related
Sep 28, 2014
I'm new to programming and i'm trying to do a certain task. I want to use a for loop to read certain data from a txt file and print them to a console. I'm trying to read student names and their grades.
Something like
3 // 3 represents the number of students.
George 97
Sarah 70
Maya 88
The data may vary but it's always in this format.
View 14 Replies
View Related