I am trying to write a program that ask the user to enter a sentence and then a word to be searched for in the sentence. The program must then search for the word in the sentence in a loop and continue to output each place the word is found. For example if the sentence is : I like pickles, pickles, pickles
and you searched for pickles it would return pickles found at 7, pickles found at 16, pickles found at 25.
I am having trouble writing the equation to make the find keep searching after each occurrence of the word being searched. Here is the code I have so far
HTML Code: #include <iostream> #include <string> using namespace std; int main() { string paragraph;
I have a small loop that gets the user input, as well as acts as input validation to make sure he or she doesn't enter a value that is not within the specified range.
The user is supposed to enter a month number. E.g. if he or she chooses February, then enter 2, or December, 12.
It works correctly if they type a number that is not in the range, but goes into an infinite loop if, say, they type a string such as "month".
Code: int main() { // Variable Declaration(s)/Initialization(s) int month=0;
I'm trying to get this program to loop the number of times I get it to input. The program compiles alright, and it does loop when I tell it too, but how do I output the grades of the multiple students?
#include <fstream> #include <iostream> #include <iomanip> #include <string> #include <cstdlib> int weighted1 = 0; int weighted2 = 0;
struct stu_dat //outside main function { int rollno; char name[45], float average;
[Code] ....
No compilation problem.when executing prompt waits for inputting rollno, but, as soon as i enter a char string it keeps looping displaying the "want to enter more data?".i cant understand what is going on,as there is no compilation problem and runs good till i input the name.
In short, I'm trying to make a CLI for a project that can take multiple user inputs add I don't exactly know what I'm doing. I'm able to get cin to take one user input, but that's all I'm sure about.
The purpose of this program is to unscramble the user's input. for example if the user entered 'ftooabll' the program would print 'football'. find the error that I am making....
Now, this only works for strings that are contained in the file wordlist. That being said, I would like this to repeat this search multiple times. Currently, the process is being repeated 7 times, but it only works on the first iteration. The code and sample input/output is below.
Sample input/output: (note: all data has been verified to be in the wordlist)
Enter string: 4132dcba abcd1234 Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba Enter string: 4132dcba
So I have to write a step in my program that reads in up to 8 variables. Simple, but if the User submits an invalid value, I have to give an error message and ask him to re-enter the value until he enters a valid number. Here's my while loop that works perfectly:
Code:
while (true) { printf(" Enter the mark given by Judge 1: "); scanf("%f", &m1); if ((m1 >= 0.0) && (m1 <= 10.0)) { break; }
[code]...
I'm not sure what to write in the else statement to make the programme understand that it has to repeat the exact same step but without adding 1 to index. Is this possible or do I have to suck it up and just use while loops instead? I'm very new to programming.
I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.
I am stuck on an exercise where i am supposed to use a loop to take user input and keep a running sum until the user enters a 0. the code i have so far is:
#include <iostream> int main() { using namespace std; int num; int total = 0; int x;
[Code] ....
The full text of the error message is: error c2678:binary'>>':no operator found which takes a left-hand operand of type 'std::istream' . and one more thing i was wondering, is there a difference between c++ and visual c++?
I'm suppose to write a program using (for loop) that asks the user to enter any amount of numbers, so that it can display the smallest and largest. My program successfully finds the largest, but it is always displaying 0 for the smallest, I think Im doing something wrong with the internalization but I dont know what to change it to.
This is what I have ....
#include <iostream> using namespace std; int main() { int amount; int count; int number = 0; int smallest = 0; int largest = 0; cout << "Enter total numbers to process: ";
My program will ask the user to enter the number of lines for the sentence "I will always use object Oriented programming. " if for example, the user enters 3, it should print out
I will always use object Oriented programming. I will always use object Oriented programming. I will always use object Oriented programming.
the second part of my program asks the user to enter the line which we want to make a typo. If they enter 2, it will replace the "I will always use object Oriented programming. " with "I will always use object Oriented programing." in the second line.
this is how it should look like but I am having trouble putting the second part together. I don't know how to remove the sentence and replace it with the second part.
Enter the number of lines for the punishment: 6 Enter the line for which we want to make a typo: 3
I will always use object oriented programming. I will always use object oriented programming. I will always use object oriented programing. I will always use object oriented programming. I will always use object oriented programming. I will always use object oriented programming.
I'm trying to write a C++ program that will allow a user to input a number from the keyboard. Then using a loop, that will perform 10 times, multiply the entered number by the loop counter. Print out the loop counter, the entered number and the product of the loop counter and the entered number. A one-time heading should be displayed before information is printed.
This kinda of what I have so far:
#include <iosteam> using namespace std; int main () { Start Declare: numScores, sum, score, avg, SENTINEL = 200 numScores = 0
[Code] ....
All the programs I have tried to make are not working?
I have a question about finding the length of first sentence in an input string.
For example, let the input string be: dream in code. community learning
The length of first sentence is 13 (blanks are included). My question is how to create conditions for multiple punctuation signs (!,?)? If while loop goes like:
I am making program that allows the user to determine how big the array size will be and then asks the user to make up numbers to fill the array. Every time run the program on Dev C++ it says "program has stopped working"
Heres My Code:
//Assignment 19 Program 2 #include <iostream> using namespace std; int main()
Still working on my first homegrown C program design . The function basically allows the user to enter a list of classes and grades and saves the list to a file to be used later in the file. The function compiles and runs through without error except for the fact that it always prints the last user entry to the *profilep file twice. Just as a note, the scanchar function is one I made to scan in one character and an end of line character to throw away the end of line char before I learned about %*c about 30 minutes ago...
Also I haven't much bothered to strengthen the function against crazy user input but I have heard using fgets and sscanf in conjunction can replace scanf and protect against weird user input. How to apply this within the program.
Code: // creates a new profile and prints it to the profile file. void newprof(FILE* profilep, const char *allclasses[ABBR_SIZE]){ int c, checker, counter; int i, a; char prof[MAX_PROF][ABBR_SIZE]; char grades[MAX_PROF][3];
This program is meant as practice. However, it is not working as intended. The for loop is meant to take the argument from the user and use it as the amount of times to loop. Instead it simply outputting: . It is supposed to output i++ but does not.
Here is the code:
main.cpp: #include <iostream> #include <stdlib.h> int main(int main, char* arg[], char* arg2[]) { int iterator = atoi(arg2[0]); std::string z = "-c";
This is an example from C++ Primer on while loops shortened for simplicity:
int main() { int value = 0; while(cin >> value) cout << value; return 0; }
When I compile and run the above code the program keeps asking for input after I input nothing but pressing ENTER no matter how many times. The only way I can get it to stop asking for input is to input something other than an int such as a char or string. Program executes as intended after that. I have googled this issue and read all seemingly relevant results and nothing seems to pertain to my exact problem. I think it may have something to do with my computer's own settings or something and am baffled as to what it may be.
I'm making a program for a MMO I play. It calculates the cash and resources needed to build certain 'modules'. I'm having trouble to do something very simple : make a loop until the user asks to break the loop. Here is what the interface looks like :
What module do you want to install?
(Examples: 'Avenger' or 'VLLT')
dd // I input this DD. COST each : 60,000 cr.
How many do you want? (Modules left:15) (NOTE : You may enter a negative number if you made a mistake) 3 // I input this Current Total Module Price : 180000 cr +6 droids
[Code] ....
The bigger code box below is a part of the code I made. What I deleted is uninteresting, it's just the same thing again : other resources, other 'modules'...
#include <iostream> #include <string> #include <algorithm> using namespace std; int main() { struct resources// Defines the amount of resources and their price
Write a program that computes a running sum of inputs from the user, terminating when the user gives an input value of 0
Using a while loop - no problem. Its only when I try to code it with a for loop that the program doesn't terminate with a 0 input. It terminates with a -1 input!!
while loop
#include <iostream> using namespace std; int main() { float input=1; float sum = 0;
Keep track of the sum of values entered (as well as the smallest and the largest) and the number of values entered. When the loop ends, print the smallest, the largest, the number of values,and the sum of values. Note that to keep the sum, you have to decide on a unit to use for that sum; use cm.