Visual C++ :: Showing Time For A User While Entering Some Characters
Dec 26, 2014
Im working on my project for college and i want to know how to add sth similar to a chronometer for user to see how much time have passed while entering some characters using cin.getline function.
View 2 Replies
ADVERTISEMENT
Jul 19, 2013
How do I prevent user from entering characters or symbols instead of numbers?
int num;
cout<<"Enter a number."<<endl;
cin>>num;
Also, how do I prevent user from entering a number instead of a character?
char c;
cout<<"Enter a character."<<endl;
cin>>c;
View 9 Replies
View Related
Feb 8, 2013
1. The debugger shows that the characters are entered into the word pointer, and when a punctuation or space character is encountered, I terminate the string with a ''. But when I use puts to print the string, garbage is printed. Why is this?
2. Also, if I don't allocate memory for word the compiler gives a warning about it being used uninitialised. But I didn't allocate memory for the array of pointers(words), and the compiler didn't give any warnings. Whats the difference between a pointer and an array of pointers?
Code:
// wordcount.c - count words.
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
[Code]....
View 7 Replies
View Related
Mar 19, 2013
How can I write my simple program so if the user enters an invalid number, The program won’t exit? I know I am supposed to use a if (cin) or if (!cin),
But I don’t know where in the program or how I should use it. Right now my Program looks kind of like this:
If (number > 1 && number < 1001)
Go through some function loops
Else
Cout << “invalid number”;
I need to write it so when the user enters an invalid number, the program would Keep asking for the right number until it's given.
View 1 Replies
View Related
Mar 6, 2015
Code:
#include <stdio.h>
#include <stdlib.h>
/*
You are to write a program that will allow a user to enter infinite numbers (greater than zero)(One number at a time). You must have a way for the user to stop entering values.Once the user stops, you will immediately display the following:
The lowest number entered is:
The highest number entered is:
The number of values entered is:
The average of the numbers entered is:
*/
main() {
int userNumber=0, sum=0, count=0, highNum=0, lowNum=0, lastNum = 0;
double average;
printf("Enter a number greater than 0: (Enter -1 to stop)
");
scanf_s("%i", &userNumber);
[Code]....
My program outputs everything I need except the lowest number entered. I have been spending a considerable amount of time on this problem to no avail.
View 4 Replies
View Related
Mar 20, 2013
Entering valid user input?
How can I write my simple program so if the user enters an invalid number, The program won’t exit? I know I am supposed to use a if (cin) or if (!cin), But I don’t know where in the program or how I should use it. Right now my Program looks kind of like this:
If (number > 1 && number < 1001)
Go through some function loops
Else
Cout << “invalid number”;
I need to write it so when the user enters an invalid number, the program Would Keep asking for the right number until it's given.
View 3 Replies
View Related
Mar 1, 2013
I'm trying to write a program where the user will keep entering data until pressing control + D. Then the it will display the mean, smallest number, and largest number.
Here are three samples of my program running.
Sample 1
Enter the price for stock 1: $ 10
Enter the price for stock 2: $ 1.555
Enter the price for stock 3: $ 3.648
[Code].....
As you can see in Sample 1, the program runs correctly. The largest number was 20 and the lowest number was 1.555. But in Sample 2, the program shows min as 15.500, where it should be showing 15.000 and Sample 3, the program shows min as 110.000 when it should be showing 55.564.
Here's the code.
#include <iostream>
#include <iomanip>
using namespace std;
[Code].....
View 5 Replies
View Related
May 10, 2013
may i know how do i read a string 2 characters at a time?
lets say i have a for loop like this
for(int i=0;i<stringLen;i++)
{
for(int j=0;j<???;j++)
{
//insert code
}
}
what i want to do is i want to read a string 2 characters at a time and store them into a vector.
View 3 Replies
View Related
Apr 24, 2013
Trying to show the Row totals and the Column totals.
#include <stdio.h>
int main() {
/* start of main */
#define NUMROWS 5 /* establishes NUMROWS as 5 */
#define NUMCOLS 5 /* establishes NUMCOLS as 5 */
int val[NUMROWS][NUMCOLS] = { {23,06,85,22,01}, /* declares array val to have 5 rows and 5 columns */
{07,33,62,17,04},
[Code] ....
I receive this message after building:
1>------ Build started: Project: WA 4 A 1 Christopher Caron, Configuration: Debug Win32 ------
1> WA 4 A 1 Christopher Caron.cpp
1>c:userschrisdocumentsvisual studio 2010projectswa 4 christopher caronwa 4 christopher caronwa 4 a 1 christopher caron.cpp(21): error C2106: '=' : left operand must be l-value
[Code] .....
View 2 Replies
View Related
Oct 31, 2014
Is it possible to show a console window in a Win32 DLL?
View 3 Replies
View Related
Nov 25, 2013
The program is showing zero in output section ....
Code:
#include <iostream>
#include <cstdio>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
const int SZ = 55;
[Code] ....
The output:
Code:
First Last Employee Hours Rate Regular Overtime Gross
Name Name Number Worked of Pay Pay Pay Pay
==============================================================
Jane Adams A1234 40.00 10.00 0.00 0.00 0.00
Mary Lincoln L8765 50.00 10.00 0.00 0.00 0.00
Martha Washington W7654 25.50 10.85 0.00 0.00 0.00
John Adams A9876 52.00 15.75 0.00 0.00 0.00
George Washington W1235 45.00 25.00 0.00 0.00 0.00
Abraham Lincoln L9087 40.25 55.00 0.00 0.00 0.00
William Tell T9876 30.00 9.75 0.00 0.00 0.00
View 12 Replies
View Related
Jan 8, 2014
My problem is ToolTips are not shown if any of the tool-bar menu items is disabled/inactive.
They are shown when all tool bar menus are active/enabled.
I am using TTS_ALWAYSTIP while creating Tool-Bar.
What to do to enable/display tool-tips always.
View 5 Replies
View Related
Mar 13, 2013
how to read characters from user and construct a sting and then extract part of it using substring?
View 2 Replies
View Related
Jan 5, 2015
I have got to create a program that will gather input from the user and then encrypt & decrypt those characters.
I'm not very confident at coding so I'm sure many parts of my code are written poorly and not following the best practice so I have written a simple version of an algorithm where the program simply adds/subtracts a value of 2 to/from the ASCII values but I have discovered the use of the rand() and srand functions but I'm unsure how to go about using them within both my encrypt and decrypt function as a single value (static variable?).
Here is my code in its entirety at the moment.
#include <iostream >
#include <iomanip>
#include <cstdlib>
#include <ctime>
#include <string>
#include <cstring>
#include <fstream>
using namespace std;
char getMenuSelection (char m);
void encrypt (char key[]);
void decrypt (char code[]);
[code]....
This code currently doesn't execute due to ' undefined reference to 'encrypt(char*) '
Question
I am asking how to generate the random number and incorporate this into my encrypt and decrypt functions.
1. Would the use of a static or global variable make this work as is?
2. Would I need to create separate class files for both functions?
View 2 Replies
View Related
Apr 20, 2015
So I'm in the process of building my 2D game in Allegro5, I'm building a side platform game and at the moment I have a sprite being able to walk left right and jump. What I want to do is put a time delay on the jump function so that when a user presses the jump button and the sprite has carried out the jump function I want there to be a 1 or so second delay before the jump button actually carries out the jump function again.
I have quite a bit of code so not sure what bits to place in here, I'm more looking for a way of doing this, so providing me code isnt really needed just a way it can be done.
Things that might be useful to know:
At the moment I have a timer initialized in allegro which is used with my FPS int to mean that my game runs at 60FPS.
I have a bool bIsOnGround which maybe could be used into this, I'm not sure...
View 2 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
Apr 23, 2014
how can i make a program which allows a user to enter an input for a time interval for example i ask a question and sets the input to be entered within 10 seconds...
View 4 Replies
View Related
Jan 20, 2013
I am writing a C++ program which takes date & time input from the user. This is then parsed into a struct such as:
struct time
{
short year;
short month;
short day;
short hour;
short min;
};
My question is: how can I convert such a struct into a time_t object, which is an unsigned long giving the time as the number of seconds elapsed since the epoch Jan 1st 1970, 00:00, as set out in time.h.
I am wondering if this can be achieved using the standard library, or whether I just need to write a function to perform the appropriate arithmetic.
View 2 Replies
View Related
Mar 22, 2013
I'm having a problem with my homework. The task is to write a program that will take time and date typed by user, and increase it by 1 minute. I should write 3 functions - first calls second function that updates time and calls third function, if time is 00:00.Time update works, but date update does not.My whole written code:
Code:
#include<stdio.h>
struct DateAndTime {
struct date {
int day;
int month;
int year;
[code]....
I should check if inputs are numbers only, so I tried including isdigit function from ctype.h library, but that didn't work either, after I was trying it for a good hour or so, but I kinda rage quit that...
View 8 Replies
View Related
Oct 22, 2013
I have to write a program for class in which users will be inputting:
start time = startTime
number of minutes = callDuration
so first off, teacher wants us to input time as a floating point number such as 09.00
How do I validate the time so that users cant input i.e. 09.61 for every hour? In other words, so the user cant input minutes 60-99 for every hour.
then, when calculating:
endTime = startTime + callDuration
how would I make endTime display a correct time in such a situation: endTime = 09.45 + 00.30
so that it displays 10.15 not 09.75
View 4 Replies
View Related
Aug 29, 2014
I'm a little lost with this program. The idea is to dynamically allocate an array and increase its size every time a new integer is inputted by the user. I believe it is a memory leak but as we have just started learning this I'm not sure how to recognise it. Sometimes I can input as many integers as I want other times 2 or 3 before it crashes. When I can input enough values i exit the loop and send it to the sort function and mean calculator function, all works fine there except the last number inputted becomes this huge value not hexadecimal though... As such I'm at a loss as what to look at next, so here you go:
#include <iostream>
using namespace std;
void SelectSort(int [], int);
float MeanCalc(int [], int);
float MedianCalc(int* [], int);
[Code] .....
View 14 Replies
View Related
Jul 2, 2013
I have no error compiling, but running my project it stops before entering a function and debugging I have an error about Segmentation fault. The function:
Code:
Mat logGabor(matriz filter,Mat filter,double r_o,double theta_o,double sigma_theta,
matriz radius,matriz theta,int cols,int rows,double sigma_r,int *padSize){
Mat rpad;
int k=*padSize;
printf("Welcome to the function"); //Here the error
...
More info: I created the matriz as : typedef double** matriz;
and a createmat function that give back a double** and in this function I allocate space for matriz and works. In the main:
Code:
Mat chr-Rpad[4][5]; //chrOrient=4;chrScales=5
for(int i_or=1;i_or<chrOrient;i_or++){
for(int i_sc=1;i_sc<chrScales;i_sc++){
//some math calculation
chrRpad[i_or-1][i_sc-1]=abs(logGabor(filter,imftt2,r_o,theta_o,sigma_theta,radius,theta,cols,rows,sigma_r,padSize));
View 6 Replies
View Related
Jan 11, 2015
I am not sure how to enter command line arguments when I run the executable of the file below. I want check an make sure that only two arguments get into the main() before running the rest of the code. I'm using bash on linux.
An example that I have tried to test for 2 arguments in command line -arg1 arg2 > ./a.out This of course does not work
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
[Code].....
View 4 Replies
View Related
Mar 17, 2013
I have a file that is like the following, with patterns of pipes in it:
Code:
||| || | |
| ||| | | |
|| || ||
I have to consider each row of pipe characters to be in blocks of 3 characters each (e.g. - positions 1-3, then 4-6, etc, etc...) but I have to capture all of the pipes, in sequence, like so:
positions 1-3 for lines 1-3, then positions 4-6 for lines 1-3, etc, etc...
How to get this done besides writing severely redundant control structures like loops, one after the other?
View 5 Replies
View Related
Jul 28, 2013
I'm trying to put an if-else statement in a do-while loop and when I put the correct answer in the if statement I get that error. Here's the program:
#include <iostream>
using namespace std;
int main() {
int answer;
char repeat;
[Code] .....
View 5 Replies
View Related
Apr 9, 2014
I'm using the Visual C++ Express 2008 and i need to pass as parameters to a function characters coded in UTF 8. My environment is Windows 7. The editor of the VC++ write in UTF 8 or UTF 16? If it writes in UTF 16 how can i change it?
View 2 Replies
View Related