C :: How To Prompt User To Scan Numbers Into Array
May 17, 2013
i need to prompt the user of my program to input numbers into an array so that later on these numbers can be added or subtracted with other numbers to form a new array. My problem is I don't know how to make the user input numbers which will then be saved into the array for later use. Here is the parts of my code that relate to the problem:
Code:
float Xv, Yv, Zv, Xu, Yu, Zu ;
float vector1[VECTOR_LENGTH] = {Xv, Yv, Zv} ;
scanf("%1f %1f %1f", &Xv, &Yv, &Zv);
printf("The first element in the array vector1 is: %3f
", vector1[0]);
The point of that printf function is to see if what they have entered is actually registering as what i want it to. This does not work however and the value for this always comes up as 0.
how to scan numbers into an array so that they can be used for later use?
View 9 Replies
ADVERTISEMENT
Apr 7, 2013
Is it possible to prompt information from user then display the result in a one dimensional array form? If yes, how should i link them together?
View 7 Replies
View Related
Dec 1, 2013
how to insert a variable for the size of array and prompt user to insert the elements for the array?
View 13 Replies
View Related
Oct 4, 2013
I'm working on a silent auction program that will scan a file and find the highest from each group of bids, then have a running total of money made throughout the auction. I'm pretty sure the rest of my code works, i'm just getting stuck on finding the largest number from the line in the file, saving it, then moving to the next auction.
input file text (first number is num of auctions, after that it's num of bids, then the bids):
5 4 100 500 250 300 1 700 3 300 150 175 2 920 680 8 20 10 15 25 50 30 19 23
Sample Output
Auction 1 sold for $500.00!
Auction 2 sold for $700.00!
Auction 3 sold for $300.00!
Auction 4 sold for $920.00!
Auction 5 sold for $50.00!
The silent auction raised $2470.00 for charity!
Code:
# include <stdio.h>
# include <stdlib.h>
# include <time.h>
[Code].....
View 4 Replies
View Related
Mar 9, 2013
Here is a simple drinks machine programm. It basically consists in the user selecting a drink that it's presented, if the user selects correctly the number representing a certain drink, the machine shows the user what was the drink he selected, after his choise the machine asks for money insertion, if the user inserts the incorrect amount of money, the machine shows an error saying that user need to insert the correct amount of money.
My problem is that, if the user selects a different number other than those presentend, the machine displays an error saying that he needs to choose a valid drink, but i can't find a way to reprompt the user again after the error has been displayed. here's the code.
// ***Drinkins Machine*** by Roxmate
#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
// initializes the variables coca, fanta, iced and drink to be used in switch function,so that the user can choose what drink he wants.
int coca = 1;
[code]....
View 5 Replies
View Related
Dec 3, 2014
prompts a User for all elements of a 3x3 matrix. Your program should then print the matrix as well as the transpose of the matrix
View 1 Replies
View Related
May 12, 2014
I am trying to write a program to get user's input but only accepts alphabetic characters, nothing else and I want it to ask the user to enter a valid word until they have finally entered a valid one. I have the following code for it but it does not work properly.
void CheckBound (char word1[], int SIZE1) {
int i;
int w1[SIZE4]= {0};
int found;
for (i=0;i<strlen(word1);i++) {
[Code] .....
View 2 Replies
View Related
Mar 1, 2013
How do I have the user enter only letters?
#include <iostream>
#include <limits>
int getInt() {
int x = 0;
while(!(cin >> x))
[Code] ....
But this function prompts the user to only input integer values. I was thinking if I could maybe try tweaking with this one so that the user could only enter letters..no luck though. So how can I have the user input letters only?
View 3 Replies
View Related
Mar 6, 2015
I'm trying to write this c++ programe:
Write a password prompt that gives a user only a certain number of password entry attempts, so that the user cannot easily write a password cracker.
Using FOR Loop. I know this can be easily done using while loop. But I want to know how to do it with for loop aswell.
Here is what I have so far:
Code:
#include <iostream>
#include <string>
using namespace std;
int main ()
[Code] ....
I don't see where the problem is.. The program just executes and does nothing.
View 9 Replies
View Related
Sep 20, 2013
how to re-prompt a user with a switch statement menu that I prompted them earlier with. There are 4 options and after the user chooses an option the menu is supposed to pop up again unless the user chooses option 4, how do I do this? For reference I'll put up my source code.
Code:
int main(){
int init_bal,choice,balance,investment, donation;
printf("Welcome!
[Code]....
View 2 Replies
View Related
Dec 24, 2014
I am simply trying to prompt a user to enter M for Male or F for Female. However, when I test run the program (what I've got so far below), any letter inputted is accepted and continues the program..?
#include <iostream>
using namespace std;
int main() {
char gender;
int maleBodyWeight;
[Code] .....
View 2 Replies
View Related
Dec 28, 2014
I need to create a program that will prompt the user for an input, then it will save their input to a file and then it will prompt the user to input "Open" and then the file containing their first input, will open up and show their input.
View 19 Replies
View Related
Aug 31, 2014
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 ....
View 2 Replies
View Related
Mar 17, 2013
I am having problems printing "->" on the beginning of each line, im trying to do it as a loop and ending it when the user types "q". also i would like to know how to ignore text from the user when the input begings with a specific character. heres what ive done so far, and not currrently working as expected.
Code:
#include <stdio.h>
int main (void) {
char prompt;
printf("~~~ FRACTION CALCULATOR ~~~
[Code] ....
View 1 Replies
View Related
Nov 18, 2013
Write a program that asks the user to prompt an Integer number and then test whether it is Palindrome Numbers or not.
The following are Palindrome numbers:
1.22
2.333
3.67876
4.44444
5.123454321
View 8 Replies
View Related
Aug 5, 2014
I'm having a problem with the two while statements in my UDF.
- 1. It will run both while loops twice...?
- 2. It now goes into a continuous loop.
- 3. When it did work, it would only return 1 value to the main()...?
#include <iostream> // for use of "cin" & "cout", endl...
#include <iomanip> // for formatting setw function
#include <cmath> // for the general math computations
#include <string> // for creating descriptive strings
#include <sstream> // used to convert a string to an integer
//user defined function
int userValue (int);
[code].....
View 1 Replies
View Related
Nov 24, 2014
I have trouble printing out the movies starting with inputing only two letters.
#include <iostream> //cout, cin, endl,getline
#include <fstream> //ifstream
#include <cstdlib> // exit
using namespace std;
const int NUM_MOVIES = 116792;
struct Movie {
[Code] ....
View 1 Replies
View Related
Feb 16, 2013
This is a winsock program designed to prompt the user to enter a domain name. The program is then supposed to return to the user a resolved ip address of that domain name. The user should also be able to enter an IP address and receive back a domain name.
While the program prompts the user to enter the domain name, all that is ever returned is error#:0
HTML Code:
// Declare and initialize variables
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#include <windows.h>
#pragma comment(lib, "ws2_32.lib")
#include <iostream>
int main(int argc, char **argv) {
hostent* remoteHost;
[Code] ....
View 12 Replies
View Related
Mar 4, 2013
This is my text file.
bak kut teh[tab]888.0[tab]989.0
spicy chicken nugget[tab]999.0[tab]978.0
I'm experiencing some problem in trying to scan and put it into an array for the food names (e.g an array for food which consist of bak kut teh and spicy chicken nugget) and another 2 array for the other individual integer into C. However there seem to be some problem with my code.
Is there a difference if I use both tab and space instead of space for all?
Code:
#include<stdio.h>
int main() {
FILE *fp;
char food[100];
char buff[BUFSIZ];
float num;
[Code] ....
View 2 Replies
View Related
Oct 21, 2013
How to write a program that will prompt and read 5 numbers. Then the program should print numbers that are larger than 80.
View 1 Replies
View Related
Sep 14, 2013
I'm expected to write a c program for this question :
Using these header files
#include <stdio.h>
#include <conio.h>
Question : Write a program that will prompt the user to enter an integer value and a character code to indicate whether they want to do a Kilogram to Pounds conversion (A) or a Pounds to Kilogram (B) conversion. Note that 1 kg = 2.2 pounds. The program should then do the necessary conversion indicated by the code and display the newly converted value to the screen.
View 1 Replies
View Related
Feb 7, 2015
I want to accept numbers from the user into an array and convert into corresponding alphabets. E.g 1 into A, 2 into B, and so on.
This is simple, but the problem is the user is supposed to enter the character # also which I want to display as it is in the output. How can I do this ? What type of array should be used - int or char?
View 5 Replies
View Related
Apr 19, 2013
I have a list of objects that I need to read information from each object to compare to a user input prompt.
#include "Passenger.h"
#include "Reservation.h"
#include "Aircraft.h"
#include <iostream>
#include <fstream>
#include <string>
#include <list>
using namespace std;
//Function Prototypes
void flightRoster(list<Reservation>&);
[Code] ....
View 1 Replies
View Related
Oct 26, 2014
Design an algorithm using flowchart or pseudo-code to prompt the user for a series of positive integer values. Calculate the average of these values and display the average at the end of the program. Assume that the user types the sentinel value -1 to indicate end of data entry.
Sample input-output:
Enter a positive integer (-1 to end) : 5
Enter a positive integer (-1 to end) : 7
Enter a positive integer (-1 to end) : 6
Enter a positive integer (-1 to end) : -1
The average value is: 6
I searched online and found out this solution however it is only for three numbers.Is there any way of modifying this to include the sum of x numbers / number of x(integers) to find the average?
View 5 Replies
View Related
Oct 31, 2014
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;
[Code] .....
View 4 Replies
View Related
Nov 18, 2014
exercise in c: write a program which calculates % of even numbers entered by a user in an array;
1) check if user hasn't entered float value; if has issue warning;
2) give the option for user to press "stop" to exit program any time.
int c,sk[100],i,sum1=0, sum2=0, rel;
printf ("How many numbers will you enter?
");
scanf ("%d", &c);
printf ("Enter %d numbers (to exit program press - stop)
", c);
[Code] ....
View 1 Replies
View Related