C/C++ :: Creating Program That Allows User To Enter Unknown Number Of Income / Expense Amounts
Feb 21, 2014
I'm trying to create a program that allows the user to enter an unknown number of income and expense amounts. The program has to us see a while loop and display the income total, expense total, and total profit or loss. I've got it really close, but I'm doing the loop wrong. It counts the sentinel value (-1) towards the total, instead of just ending like it is supposed to.
#include <iostream>
using namespace std;
int main() {
//declare variables
double incomeInput;
double expenseInput;
double incomeTotal=0;
double expenseTotal=0;
[code]....
View 5 Replies
ADVERTISEMENT
Nov 3, 2013
I need to write a program that will allow the user to enter a number "n" and the program tell you that the nth prime number is .....
EXAMPLE
user enters 55
printf("The 55th prime number is %i", variable");
View 1 Replies
View Related
Mar 23, 2014
Write a C++ program that asks the user to enter an even number only. If the user enters an odd number the program should use input validation to ask the user to enter another number.
- The user can enter as many numbers as he wants
- The program should also keep a count of how many numbers entered and display how many odd and even numbers entered.
View 1 Replies
View Related
Jun 27, 2013
Write a program that prompts the user to enter an item#, the program should determine if the item is in the file and print the price of the corresponding item. If the item is not in the file an error message should be printed.
All I have so far is
string item_no=0;
cout<<"Enter a item#";
getline(cin,item_no);
if stream openData;
I need to finish the rest in pseudo code
View 2 Replies
View Related
Aug 22, 2014
I am trying to write up something to have a user to enter a four digit number. Only four digits, Ex: 0001, 0116, or 9999. There is no getting around the selection 0001 or 0002. I understand if not done correctly, the first three 0's will be ignored.
I've been just playing around with what I have below but I just don't remember how to do it nor can I find a good example online to figure it out. I know it is not correct just typing to try to remember. I am aware that it is gibberish right now, this is just me brainstorming.
int number;
cout<<("Please enter the four digit number(Ex: 0001):
");
cin>> setw(2) >> number;
cout<<)"Please enter four digit date. Two digits for month and two digits for year:
");
cin>> date;
if (number< || number > 30)
cout << "Invalid choice. Try again." << endl;
cin.clear();
View 2 Replies
View Related
Mar 22, 2013
I'm stuck because I can make the calculator just find but the user will have to press enter after every number, what is s solution to this?
#include <iostream>
#include <string>
using namespace std;
int a = 1, b, c;
string symbol;
int multiplyFunction();
[Code] .....
View 6 Replies
View Related
Dec 4, 2014
I don't know how to ask the user to enter the date in this format (DD/MM/YY) and ISBN number with hyphens.
After user enter date and ISBN number, it should look like this:
Date: 5/24/12
ISBN: 0-000-12345-0
#include <iostream>
#include <string>
using namespace std;
int main() {
string date;//MM/DD/YY Format
[Code] ....
View 7 Replies
View Related
Jun 7, 2013
So my inventory program runs fine as far as I can tell. Except when entering "Amounts" with more that 1-precision . ie
Amount Entered : 25.99 // Problem
Amount Entered : 25.9 // No Problem
When entering say 25.99, the rest of the file is jibberish. but 25.9, the rest of the file is fine
Code:
#include <stdio.h>
typedef struct toolRecord{
int record_num;
char tool_name[16];
int quantity;
double price;
[Code] .....
View 5 Replies
View Related
Jul 2, 2013
I am trying to make a program that will allow a user to enter their name, from this point, three options should be present for the user to choose, then from that point, two more options should be present. I have if else statements in a switch case and I get the "undeclared" error for the a in the first " if(specificage == a) ".
NOTE: I use Code::Blocks.
Here is the code:
Code:
#include <stdio.h>
#include <string.h>
int main(){
char name[50];
char ageclass[50];
char specificage[50];
[Code] ....
View 3 Replies
View Related
Feb 11, 2013
B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.
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
Dec 12, 2013
a program that allows the user to enter a statement and outputs statistics; number of vowels, number of constants, percentage of vowels and constants, number of words, number of punctuation characters
View 2 Replies
View Related
Nov 8, 2013
Write a program that prompts the user to enter an integer and then displays that integer as a product of its primes and if it is a prime then it should say so? Above is the question I have been given
#include <iostream>
#include <vector>
using namespace std;
int main () {
int num, result;
cout << "Enter A Number " << endl;
system ("pause");
return 0;
}
This is what I have so far, do I have to use a for loop, a while loop or a do loop,
View 7 Replies
View Related
Jan 21, 2014
Write a program that asks the user to enter a student’s grades on four exams. The program should display the four grades and the average of the four grades,rounded to the nearest tenth. To add the grades, use a variable called total_grade, which you should initialize to zero.As the program prompts for and obtains each grade, add the grade to total_grade using the += operator.
View 3 Replies
View Related
Oct 7, 2013
The output I'm getting here just counts every letter in the sentence and counts them as vowels. I'm trying to make the user defined function return the amount of vowels within the sentence.
#include <iostream>
#include <iomanip>
#include <cmath>
[Code].....
View 4 Replies
View Related
Oct 18, 2014
My assignment is : Please use C type strings ( array representation of strings). Write a program that will ask the user to enter a string. It will then regard that string as a worked-on string and allow the user to perform the following editing functions on it:
s – search
i – insert
a – append
d – delete
a – append
d – delete
r – replace
e – exit
s – search
This option will allow the user to search for a specified string in the worked-on string. If the string is
found, it will display the starting index (position) of the searched string in the worked-on string.
here is what i have so far.
#include <iostream>
#include <cstring>
using namespace std;
int main() {
char a_string[80];
[Code] .....
View 4 Replies
View Related
Oct 12, 2013
You enter decimal number into the program and what base you want. The integer part of the decimal is being handled fine, but the decimal is not.
For example, I enter 15.6847 and base 10, which means I'm going from base 10 to base 10. It spits out 68469999999999 for the decimal part. (Do not worry about the first block of numbers. The second block seperated from the first by a space is where the decimal will appear in order.)
#include <iostream>
#include <string>
#include <math.h>
using namespace std;
int baseConverter(int, int, int *, int *);
[Code] ....
View 2 Replies
View Related
Oct 5, 2013
Okay, so my assignment for my C class is to generate a program that will allow the user to enter data for a stock and calculate the amount of stocks that ended up being positive, negative, and neutral.I tried to do this using one stock, here is my code;
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
Code:
void main()
{
float Neg;
float incst;
float shrs;
float bpps;
float crnt;
float crntcst;
float yrfes;
float pft;
float tpft;
}
[code]....
View 6 Replies
View Related
Aug 9, 2012
I'm trying to create a program that creates random numbers. I looked through some examples and this is what I came up with. The time identifier seems to be undefined yet I see no reason it is undefined.
Code:
#include "stdafx.h"
#include <iostream>
using namespace std;
int main() {
//Re-seed the random-number generator
time_t now;
[code]...
here's my error code..
1>------ Build started: Project: bake, Configuration: Debug Win32 ------
1> bake.cpp
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(8): error C3861: 'time': identifier not found
1>c:usersjonbecherdocumentsvisual studio 2012projectsakeakeake.cpp(9): warning C4244: 'argument' : conversion from 'time_t' to 'unsigned int', possible loss of data
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
View 2 Replies
View Related
Apr 23, 2013
In class we were asked to create a C++ BTree program that would allow a user to input the following data types and then store said data in a .txt file:
0. ID 8 bytes
1. First name 30 char
2. Last Name 30 char
3. Street Address one 30 char
4. Street Adress two 30 char
5. City 30 char
6. State 20 char
7. Zip 10 char
8. Country 30 char
(I'm not particularly asking for full code, pseudo code would also be great). I had a great deal of my work done, unfortunately, the computer I was working on crashed, corrupting my files.
View 4 Replies
View Related
Apr 6, 2014
I am currently having problems creating a loop that will allow my user to choose to return to the beginning of the program or quit.
#include <iostream>
using namespace std;
int main() {
int j;
do {float a;
cout << "+----Welcome to Basic Operations----+
| Select Your Operation |
[Code] .....
I have not yet finished designing the interface for a couple of the operations, but right now i am hung up on trying to return to the beginning. I believe it is because the j was defined inside do and isn't carried out of the do statement for while.
View 13 Replies
View Related
Dec 2, 2012
i dont usually write console programs, and i cant seem to find out how one parses an unknown number of arguments with cin.
the program receives an unknown amount of integers in stdin, and i need to parse them withouth hanging.
Unfortunately, stdin is a async. stream and blocks, if it doesnt find any integers left.
I cant use peek() or seek() either, as both are async, too, (which makes me wonder what their exact use is?).
View 3 Replies
View Related
Mar 1, 2015
I have a file with such a format:
string string 8 7 2
string string 7 12 19 -4
string string 1
As you can see I don't know how many numbers there are at the end. I have this code now:
while(!in.eof()) {
kr = 0;
getline(in, pavard, ','); getline(in, vard, ','); getline(in, gr, ',');
while(in.peek()) {
in >> k;
kr += k;
}
in.ignore();
}
in.close();
I tried various combinations with peek() function, but nothing worked.
View 2 Replies
View Related
Jan 16, 2013
Consider the following piece of Code:
int ReadNumbers() {
int num;
vector<int> x;
cout << "Enter Numbers" << '
[Code] ....
The while loop is expected to terminate when the user provides an Invalid Input. But this while loop behaves unexpectedly when the user provides a 'Newline' input (by pressing Enter) and becomes an infinite loop. How can I prevent this from happening? Also I've heard that expecting invalid inputs isn't good code design. Is this true? If yes, then how can I solve my question without expecting Invalid Inputs?
View 10 Replies
View Related
May 1, 2013
So I'm making setTimeout and setInterval functions.
I have this remember function (that is part of Timing class) which takes a function pointer and a void pointer, which are remembered in that object.
Another (timing) function of that object is called in every loop of the program and when specific time passes that function calls the remembered function whit the remembered void pointer as argument.
The problem is that the functions that need to be called require unknown multiple parameters, so what I need to do is make a new class that will store the needed arguments. I make the function that needs to be called and that storage object and pass pointers to them to my remember function, when the remembered function is called it stores the data from storage object in new variables and dose it's thing.
View 3 Replies
View Related
Oct 15, 2013
So I'm trying to make a program that asks the user for a number and then prints a statement the same number of times the user entered. 3 different statements, using the 3 loops (for, while, and do while). I made the program but for some reason the statement from the do while loop goes off infinitely.
MY CODE:
The error:
View 8 Replies
View Related