Write a program that will ask the user to enter some words followed by the word END.
Input the words into an array and then output the following statics:
the list of and the count of how many words were typed (not counting END) -- Test 2
the list of and the count of how many unique words were typed -- Test 3
the list of sorted unique words (in alphabetical order) -- Test 4
the list of sorted unique words along with frequency counts for each word -- Test 5
See the sample run below:
Please type in some words.
Type END and return when you are finished.
red green blue
RED red blue green blue orange red
reg apple banana banana
END
You typed the following 14 words:
red, green, blue, RED, red, blue, green, blue, orange, red, reg, apple, banana, banana
You typed the following 7 unique words:
red, green, blue, orange, reg, apple, banana
Here are those same unique words sorted:
apple, banana, blue, green, orange, red, reg
Here are those same unique words sorted with a count of how many times each was used:
apple: 1
banana: 2
blue: 3
green: 2
orange: 1
red: 4
reg: 1
I am having problems understanding where this code is wrong as I believe that I am not receiving the correct outputs. I have truncated the code to the most pertinent.
The algorithm asks that every value in array1 be divided by array2
and if that value is less than the ratio * array3 (percentage filter) then output.
I have no problem with the code with the exception of abs(ratio*array3[m]
Assuming that the ratio = 1 then all values get outputted, I want the array1 (first value) to have the first value in array3 assigned to it, the second value in array1 to have the second value in array3 to be assigned.
So:
array1 (1.0) with array3 (0.05) array1 (2.0) with array3 (0.06) etc. or array1 (1.0) with array3 (0.05) array1 (3.0) with array3 (0.07)
I need to run some basic statistics on about ~150 tables that are currently in dBase format. Rather than use excel to do them all individually, i was told to use s+ and write a code to loop through them, but I have never written any code and my experience with spotfire s+ is limited (the stat software i have available) ....
I have a problem with my code while trying to simulate a snakes and ladders program. The objective of the program is to simulate many games (100000+) to gain statistics:
1. The most likely number of rolls. 2. The mean value of the number of rolls. 3. The most common square, C, on which a token may come to rest. i.e. move on to. 4. The probability of coming to rest on square C. 5. The least likely square on which a token may come to rest and what is the probability of this occurring. 6. The distribution in the number of rolls needed per game presented as a normalised graph. 7. The minimum number of rolls of the die - called Nmin. 8. How many different paths (unique sequences of die rolls) take Nmin rolls to complete the game?
However my program (on Tenacious C) doesn't seem to run at all...
I have run it on internet compilers and other compilers but it must work on Tenacious C.
Below is the code I have at the moment, it works fine when stepped through or ran on a different compiler.
How to create code to answer the 8 points above. For instance, to get point number 2. I must find the total rolls divided by the total number of games, but am not sure how to do this.
Code: #include <stdio.h> #include <math.h> #include <stdlib.h> #include <time.h> #define NUMBEROFGAMES 10 int GetThePositionOfMovement(int CurrentPosition, int dieValue);
Basically I have a text file called words. I'm supposed to extract a word randomly form the file and have the user guess the word. If they guess the word correctly in x number of tries they will receive the definition.
I'm having trouble receiving that random word and I'm getting the definitions from the file.
This is what is in the words.txt file apple#the usually round, red or yellow, edible fruit of a small tree boat#a vessel for transport by water horse#a solid-hoofed plant-eating domesticated mammal with a flowing mane and tail, used for riding television#a system for transmitting visual images and sound that are reproduced on screens soup#a liquid dish, typically made by boiling meat, fish, or vegetables, etc. bottle#a container, typically made of glass or plastic and with a narrow neck barber#a person who cuts hair toast#sliced bread browned on both sides by exposure to radiant heat radar#a system for detecting the presence, direction, distance, and speed of aircraft, ships, and other objects red#of a color at the end of the spectrum next to orange and opposite violet
I am building a linked list and i need to display function i have. The display function displays all the letters of the word entered instead of the word itself. below is my struct, one of my functions and the display function.
I'm learning programming, and C++. I've got a question, but I couldn't solve my problem so far. I need to use arrays and only basic stuff to solve this:
Create a program that reads a word from the user and then print (cout) this word on contrary. It's simple, I know, but I can't do it,. I've tried some stuff but I don't get how I will get the proper values to do this. All I know is that I can use variable.lenght().
I've taken part the text into 1 word per line, but I can't figure out how to printf every word only once and then add (%d) in the end to show how many repetitions of that word there are.
Code: #include <iostream> #include <stdio.h> #include <stdlib.h> #include <string.h> using namespace std; int main(){ char *oneword;
I have text (string) and I want to find a given word (it's ok!) and then insert another given word after the first word. The original string is beeing copied into a new string. But something is going wrong!!! Where is my mistake?
(I have some patches...)
Code:
#include <stdio.h> #include <stdlib.h> #include <string.h> //insert "new_word" after each occurence of "word" int main(){ char A[100]="In the sentence words the and the.";
i'm making a program for basic data entry.i have also included search feature which uses strcmpi() function.if i have a file name'report on tigers' and someone searched for 'tigers' then that person will not find the required file.any way i can overcome that ?
I define "Comwords" as a string, but apparently it takes the members as chars, then I can't set strings in a structure equal to the chars.
I see to also be having unknown problems with the ComMAL array and loading it values into another element of the same structure.
How to correct this? I was thinking of casting char elements as strings, but could find no reference in my library book regarding how to do that (lots on casting int's a doubles...)
Code:
int _tmain(int argc, _TCHAR* argv[]) { int comm = 10; int targ = 5; int death; struct AI_WORDS
Using a for loop, construct two 100 element arrays, x and y, such that element i of x stores the value sin(2*pi*i/100)) and the corresponding element of y stores cos((2*pi*i/100)). Print the values stored in the elements of x and y as you calculate them.
I have attempted to solve it but I'm not sure why the value 0 is only being printed, maybe I haven't assigned sin(2i/100)) and cos((2i/100)) to the arrays properly?
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
I have an assignment that calls for a C program using a for loop AND a while loop that will receive an integer (called daNumba) and double it -- Using the integer the program will call the sumFor function and then the sumWhile function. These functions will both sum the values from daNumba to (daNumba * 2) ifdaNumba is positive. If daNumba is not positive it will add the values from (daNumba*2) to daNumba. Both functions will receive the value of daNumba and return a summed value. The only difference between the 2 functions is that sumFor will only use for loops and sumWhile will only use while loops. We are not to use arrays.
The program compiles without error. So far my while loop works for positive integers, but not with a negative integer (I have it commented out) I cannot get the for loop to work properly This is what I have so far -- I am stuck....
Code: #include<stdio.h> #include<stdlib.h> #include<math.h> int main () {
int main ( int argc, char *argv[] ) { int P[150] = {}, i, j; for ( i = 2; i <= 150; i++ ) {
[Code] .....
Using gdb, I noticed that the variable j keep going back to initial value after the interior for loop condition returns false. Why doesn't this for loop terminate right away?
I've just started learning the C language, and I'm stuck on something that is probably quite simple.how to get IF statements working within WHILE loops. My code is below. I am trying to write a program to count the number of words in a sentence, and obviously stop counting after a full stop has been entered. I created a variable called 'spaces' which will increase by one after the user enters a space. However, when the IF statement is in place, the loop never terminates, even if I enter a full stop. When I delete the IF statement, the loop functions correctly.
Code:
#include <stdio.h> int main() { char x; char a; char y; int spaces = 0; }
What output would you expect from this program?" The output was not what I expected. I've psuedo-coded this out and I'm still missing something.
Code:
#include <stdio.h> int main () { int numbers[10] = { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; int i, j; }
[code]....
The output: Code: 1 1 2 4 8 16 32 64 128 256 So when I look at this first loop I see that j = 0, which is less than 10, so then the program statement should commence, which is another for loop. So in this inner for loop I see that i = 0, which is not less than j, so this loop should terminate. Then the value of j increments by 1 and the first go around of the loop has completed.
Now I see that j = 1, so this is less than 10, and the inner for loop commences once again. This time though, i actually is less than j, so numbers[1] = numbers[1] + numbers [0], or numbers[1] = 0 + 1. Now the value of i is incremented by 1 and the first go around of this inner loop has completed. Then the value of j increments by 1 and another go around of that loop has completed.
So now j = 2, i = 1, and numbers[2] ( which is 0 ) = numbers[2] + numbers[1], or numbers[2] = 0 + 1. I was expecting the output to be an array full of 1's. However this is not the case..
I need to make a for loop without: using the math functions like pow, sqrt, etc. or an if-statement.I can only use the basic arithmetic functions like +,-,*, and.The for loop needs to display: 1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192 as the result
How do I make it so my loop works? This is what I have and it doesn't work...and I have no clue how to continue...
k = 0; //k is an int and I have declared it in the beginning of my code for( k = 0; k < 13; k++ ) { printf ( "%d, ",k ); k = k * 2; } printf("%d", x);
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?
im trying to make a program which will tell which key i pressed and then it will print in msgbox, but i cant figure out how to read the key in loops, like i tried getasynkey (imported to my c# console app) with value around -32676 or -32767 i ( i found it on internet) and it only shows the key once, i want to do like while my key is pressed, then it will spam my console with key pressed, is there any way to do it?