I tried to scanf the input by the user into the function but it does not read my input. Read on one of the thread, it said that to scanf a input into a double, need to use %1f instead to %d (which normally used. I tried changing it to %1f and it still did not work.
Code:
#include <stdio.h>
#include <math.h>
/* function main begins program execution */
int main( void )
{
double amount; /* amount on deposit */
int i; while (scanf("%i", &i)) printf("%i ", i); printf(" done ");
i tried several combination of Ctrl+D and "Enter", it's not terminating, Ctrl+C just "cancels" the whole thing without printing "done", i'm running this on linux installed on a PC
Code: #include <stdio.h> int main(void) { char c; int i=1; while (scanf("%c", &c)==1) printf("loop sequence %i: %c(%i)
[Code] ......
Done it seems a "carriage return" serves two purposes here, one is to signal the program to read in the character typed in before the "carriage return", another serves as a second character typed, how can i do this cleanly, that is without having to use a "carriage return" as the second character to signal "I've typed in the first character already".
The issue that I'm having is that when I run this part of the code it seems to enter the if statement and set it to 0 when comparing the array to the input.
What I want it to do is to search the array for the grade, set it to zero, and then exit the loop in case there are any repeat grades. It always sets the first number to 0 and then exits.
//Below is the prototyping for the array
int grades[14] = {60,50,50,20,75,90,0,0,0,0,0,0,0,0};
//There is some code between here, but it is probably not relevant so I didn't post it.
printf("Enter the grade that you want to remove. Press Enter after each input."); printf("Enter 0 to exit: ");
[Code] ....
I didn't mean to leave the "prototyping" part in the code. I was initially going to put the function prototypes in there, but decided it wasn't necessary for the question.
Firstly, I'd like to say that I'm relatively new to functions and my course standards state that I'm now supposed to relay information from the user to the program via functions, this means that I'm no longer able to use 'printf/scanf' combos in the main function.
Is it possible to do it via functions? I've tried the following method for example, but to no avail.
Code: #include <stdio.h> int getlowR(); int main(void) { getlowR();
[Code] ....
I think the following works but then lowRange is native to the function, isn't it? How can I use it outside the function? For example, how would I go about actually printing the value acquired by the function in main?
How I can let the user input a certain operator into this calculator function?. I would like to use cin to input the operator if possible because it is one of the only input commands I know.
// Calculator.cpp : Defines the entry point for the console application. // Calculates the value of two numbers based on the four main operations.
#include "stdafx.h" #include <iostream> int add(int x, int y); int subtract(int x, int y); int multiply(int x, int y); int divide(int x, int y);
How to get this thing to work. All i need to do is ask user to input a name and then it brings out the line from the .txt file containing the information.
For example in my case I'm doing a member search function I'm required to ask user to input the name of the customer and then print out all the details (which consumes 1 text line in the .txt file)
Here is the code, This is the write to text file method (100% working)
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 trying to make a character array, and be able to custom fill it by using the scanf() function to ask the user for each character spot in the array.
Code: #include <stdio.h> int main() { int i; char character_array[11]; char *charpointer; charpointer = character_array;
[Code] .....
And this is the output i get when i run it:
Code: root@kali-Tulips:~# ./myown what letter would you like in the [0] spot of the array? : a what letter would you like in the [1] spot of the array? : what letter would you like in the [2] spot of the array? : b what letter would you like in the [3] spot of the array? : what letter would you like in the [4] spot of the array? :
[Code] .....
Obviously I'm trying to grasp C programming and am very new. I don't understand why this isn't working, and i think its more than my lack of knowledge of C syntax. I believe the correct memory is allocated but when examined with gdb i don't find what i expect....
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()
In this simple end-of-chapter problem, the ages of two people are to be compared and determine who's older. The problem I'm experiencing is that the second user name input is being skipped and going straight to the second users age.
So while running the program it looks something like:
What is user ones name? <input name> How old are they? <input age> What is user twos name? How old are they? <input age> <if statement result>
Here's my code:
Code: #include <iostream> #include <string> using namespace std; int user_one_age; int user_two_age; string user_one_name; string user_two_name;
So I've got this form that a user puts in a numeric value into a text box. This value then has to be placed into a byte string of data so that it can be transmitted over as a packet. Bellow is what I have so far:
Code: Byte[] OUTBuffer = new byte[65];//Allocate output memory buffer Byte[] INBuffer = new byte[65]; //Allocate input memory buffer
if (setmSpeed == true) { OUTBuffer[0] = 0; //Not used, must be set to 0 OUTBuffer[1] = 0x85; //Command mode
[Code] ....
I've put in red the area where I'm having issues. I've tried different methods and have not been able to get this working yet. It only works if I speciffy the value manually as with OUTBuffer[1] = 0x85;, but I want byte 2 of OUTBuffer[] to be set with what I put in the text box.
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:
So im working with forks and creating 2 fork processes. One child and parent. What im trying to get the child to ask me for a value. Then the parent would start to figure out the value and keep trying. Once it figures it out its tells them you got it and simply stops the program. I cant seem to get the program to keep guessing and stop when the number is found which sends a sigint. Here's what i have so far.
I have this code here that counts the number of alphabetic letters the user's input,the number of characters total, the number of words and the number of "the" that was used. However now I need to alter the user's input to have two spaces after the end of each period, no spaces between a word or comma and each sentence has to have a capitalized letter and display them at the end. And I'm stuck on the altering part. I briefly started the 2 spaces after each period but it won't display anything.
#include <cstring> #include <iostream> using namespace std; int main ()
I have written a program and i had to pass an array into a function and now i have a variable for the subscript of the array and i was the user to input data, specificlly a string, more specifically first and last name without having to create two arrays, i have to do this with other things in the program as well, here is part of the program:
int addFunc(const int totNum, string city[],string state[],string street[],string name[], int addNum[],int zip[],int telNum[],double bal[],int dateLp[], int addCount, int accNum, int usNum)//function will add a new account { int countAf = 1; if (usNum < 20)
[Code] ....
it should be able to take firstname space lastname
I need to make a program that takes in a user’s number and keep dividing it by 2 until it is 1.I need to display the division steps ...
I do not know how to keep making it divide by 2 until 1. I tired this but it obviously did not work..
Code: #include <iostream> using namespace std; int main() { //User Input int input,total; cout <<"Enter A Number To Be Divided By 2 Until 1" << endl << endl;
since around 2hours im really fighting with the cin command.It doesn't matter what exactly im trying, it's just not waiting for user input and keeps directly using 0 as "entered" value.
int Value; cout << "Enter a new value: " << endl; cin >> Value; cout << "The value has been set to: " << Value;
I'm trying to make a simple program that accepts user input, simple stuff. When the user (me) enters a number to be sent to the console and i press enter so it accepts the data, it closes the command prompt and thus ending the program. I just need to find a key that i can use to continue but doesn't close cmd.
My parameters are that the users input has to be from 1 to 9 and the same number can't be entered twice. How do i modify this code to make sure that the user did those things or an error message should appear that their input is invalid.
#include <iostream> using namespace std; int main() { int square[3][3];
Create a program that will ask the users name, age, and reddit username. have it tell them the information back, in the format: your name is (blank), you are (blank) years old, and your username is (blank).
My program outputted H 0 and an upside down question mark. I was thinking that maybe the error in the program was that i was supposed to use %s instead of %c but im not entirely too sure.
how to see if what the user says is in the dictionary. I do not know what to put in ContainsKey() or after the information in console.writeline. I just want the user to type in the key then see if it is in the dictionary then print out the value if it is.
while ( Console.ReadLine() != "exit" ) { Console.WriteLine("Type in word"); if (clothingDictionary.ContainsKey()== true) { Console.WriteLine("key is {0}, value is {1}", );