C++ :: Using While Loops That Prompts User For A Set Of Integers

Jan 30, 2015

-Write a program using while loops that prompts the user for a set of integers.

-Your program will ask for one integer at a time. If the number 0 is entered, the list is complete and your program will output two results: the sum of the even integers and the sum of the odd integers.

-After each integer is entered by the user, your program will print out whether the integer entered by the user is less than, equal to, or greater than the previous integer. Assume for the first integer entered by the user that the “previous integer” was 0.

-Your program must handle a variable number of inputs (in other words, you cannot hard code for the test cases).

This is what I have so far:

#include <iostream>
using namespace std;
int main() {
int a;
int b;

[Code] .....

View 2 Replies


ADVERTISEMENT

C++ :: Program That Prompts User For Int Value?

Sep 23, 2013

I'm making a program that prompts a user for an int value. The value input by the user must be a multiple of 16. If it is not, I must return an error message.

View 5 Replies View Related

C++ :: Compiler Skipping User Prompts?

Mar 24, 2014

the problem that I'm running into is that the compiler skips to the end when I put my initials in //User input > "Initials"

I'm using Microsoft Visual C++ 2010 Express.

Here is the assignment:

Plan and code a program to do the following. You found an exciting summer job for 5 weeks. It pays $15.50 per hour. You will input the number of hours per week that you worked and then compute your total earnings. You must pay taxes of 14%. After paying taxes, you will spend 20% of your money on cloths and 5% on school supplies. After buying clothes and supplies, you will use 25% of the remaining money for savings.

Input

Your 3 initials and the hours for each of the 5 weeks. Use the following numbers of hours for your first test 25, 30, 20, 23, 22.

Calculations

Gross pay is the rate of pay times the sum of all hours you worked. Use CONSTANTS for each of the following rates:

Tax rate 14% of the gross earnings
Clothing 20% of earnings after taxes
School supplies 5% of earnings after taxes
Savings 25% of earnings after taxes and expenses

Output:

Output your initials, total hours worked, gross earnings, taxes, net earnings after taxes, clothing expense, supplies expense, amount going to savings and amount left to spend. Output must be aligned to the right as shown with 2 decimals in all numbers. Sample output:

Initials ABC
Total Hours Worked 120.00
Gross Earnings 1860

Taxes paid 260.40
Net Earnings 1599.60

[code]....

Turn in:Be sure your output file contains user prompts and what was entered by the user. In addition to the results of your program processing. Run with above listed data.

Here is my code

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
double Initials, TotalHours, GrossEarn, TaxesPaid;

[code]....

View 6 Replies View Related

C++ :: Program That Prompts User To Specify People And Cars

Feb 10, 2014

Implement a class Person with two fields name and age, and a class Car with three fields:

The model
A pointer to the owner (a Person*)
A pointer to the driver (also a Person*)

Write a program that prompts the user to specify people and cars. Store them in a vector<Person*> and a vector<Car*>. Traverse the vector of Person objects and increment their ages by one year. Traverse the vector of cars and print out the car model, owner’s name and age, and driver’s name and age.

#include <iostream>
#include <vector>
#include <conio.h>
#include <string>

using namespace std;
class Person {

[Code] ....

View 7 Replies View Related

C++ :: Program Prompts User To Select A Number Between 2 And 12 Twice?

Oct 8, 2014

Here is the whole code:

#include <iostream>
#include <ctime>
#include <cstdlib>
//This program prompts the user to select a number between 2 and 12
//computer throws two dices
//player win if selected number matches the sum of the two dices thrown by computer

[Code] .....

View 6 Replies View Related

C++ :: Program That Prompts User For 10 Grades And Then Find Average

Feb 24, 2015

I need to write a program that prompts the user for 10 grades and then find the average. I have that part but I need to average to not include -1. How can I tell the program to not calculate -1 into the average.

#include <iostream>
using namespace std;
int main() {
//Declare variables
float grade[10]; // 10 array slots
int count;
float total = 0;
double average;

[code].....

View 1 Replies View Related

C++ :: Write A Program That Prompts The User To Enter Integer?

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

C++ :: Write Program That Prompts User To Enter Item Number

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

C++ :: Create A Program Which Prompts For User Input Of Current And Birth Date

Sep 27, 2014

I have an assignment in which i must create a program which prompts for user input of current and birth date, which will compare said dates and output if its your birthday or not. I've completed a large portion of it, but cannot figure out how to get the user input of month as an integer such a 2 into February.

#include <iostream>
using namespace std;
class DayOfYear {
public:
void input();

[code]....

View 1 Replies View Related

C# :: For Loops To Make User Defined V Shape Output

Jul 29, 2014

Write a program to ask a user to input a symbol from the keyboard and to output that symbol in a n X n/2 sized V where n = the width of the V. You must use a loop to process the data

I am stuck at trying to figure out how to do the actual output formatting. This is where I am sitting currently.

string character = "";
int vheight = 0;
Console.WriteLine("Enter the character you wish to use for your V: ");

[Code]....

so Im really just a bit stumped on how to get the actual V shape to be formatted..

View 14 Replies View Related

C :: User To Enter 4 Integers Which Get Stored In Array

Mar 3, 2014

For my code, I want the user to enter 4 integers, which get stored in an array. Here are the lines I wrote relevant to this part:

Code:
printf("Enter 4 integers:
");
scanf("%d %d %d %d," &a, &b, &c, &d);
z[4] = { a, b, c, d};

Would this be correct?

View 5 Replies View Related

C++ :: Program To Create Integers As User Requests?

Nov 19, 2013

I know it would be easier to create an int array, but I want the program to create integers as the user requests. For example, if the user enters 4, the program creates 4 integers with the names input. Each integer is better as an individual integer, not an element in an array.I'm not sure if this is a possibility with C++.

View 3 Replies View Related

C/C++ :: Program That Keeps Reading Integers Until User Enters -1

Nov 21, 2014

This is the problem :- Write a program that keeps reading integers until user enters -1, then it prints the maximum and the minimum among all numbers (-1 should be ignored).

View 14 Replies View Related

C :: Program That Asks The User To Type 10 Integers Of Array?

Mar 2, 2014

Write a program that asks the user to type 10 integers of an array. The program will then display either "the array is growing", "the array is decreasing", "the array is constant", or "the array is growing and decreasing."

(Hint: compare consecutive numbers in array and check whether it is increasing or not or constant) I wrote the program very well, but do I have to use "bool" like in c++ ? I haven't known how to code in c++ yet.So, I don't want to use "bool" in C.

I also wrote code about it but it looks like backslash and one,two,three,four,five how can I do it like this ?

View 4 Replies View Related

C++ :: Add Or Remove Integer To A Chain Of Integers Created By User

Mar 25, 2014

I got everything in this code running except for my remove function. What the project does is adds or removes an integer to a chain of integers created by the user. My add function works the first time but after that if I try to remove or add I believe it is pointing to the improper location and I don't know how to fix this....

Here is my code:

Header:
// adds "number" to the array pointed to by "arrayPtr" of "size".
// Note the size of the array is thus increased.
void addNumber(int *& arrayPtr, int number, int &size);
// removes a "number" from the "arrayPtr" of "size".
// if "number" is not there -- no action

[Code] .....

View 12 Replies View Related

C++ :: Output Multiplication Table From Two User Input Integers Between 2 And 10?

Jan 14, 2015

So I'm supposed to write something that will output a multiplication table from two user input integers between 2 and 10.

For example it should display like this is the user inputs 4 and 5

1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20

I was hinted to used two for loops and this is what I have thus far, what I can't figure out is how to display it like the example.

#include <iostream>
using namespace std;
int main() {
int num1;
int num2;
cout << "Enter two numbers between 2 and 10." << endl;

[Code] .....

View 2 Replies View Related

C :: Program That Takes Multiple Integers From User And Finds Minimum Value

Jun 11, 2014

Write a C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.

This is a sample output. Notice how the program prints a counter (1, 2, 3, ) for user keep track of how many numbers were entered so far. Include this feature in your program.

I have tried different ways to get the result from while loops, do while, and if-else statements. We have not done any max/min problem in class and the book was kind of vague. We have not learned arrays yet in class and I can't figure a way to compare the integers the user inputs as it is an infinite(from what I am reading) amount aloud. The problem I am seeing is the loop works and stops with the sentinel value but the INT_MIN is using the sentinel value. I also have not addressed the input of negative numbers yet with the first program I wrote, maybe one of my problems.

Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>
/*****start program*****/
int main() {

[Code] ....

I have also tried this way as well, min value still comes back as -1 the sentinel value, and the else statement is being ignored. I am sure it is something silly but I am lost and confused at this point.

Code:
/*File:HW2Q3.c,
A C program that takes multiple integers from the user and finds the minimum value. The numbers entered by the user are positive integers. When the user is done entering all the numbers, the user enters the sentinel value of -1.*/
/*header files*/
#include<stdio.h>
#include<limits.h>

[Code] ....

View 13 Replies View Related

C :: Program To Get Series Of Integers From A User And Storing Those Values Into Array

Feb 10, 2013

The problem deals with writing a program to geta series of integers from a user and storing those values into an array. Then use a function called selection_sort, when given an array with n elements, the function must sort the array from smallest to largest values.

I have code, and im trying to get it to compile but im getting these implicit declaration errors and conflicting types. Here is my code and the compiler errors.

Code:
Compilation started at Sun Feb 10 20:14:48

gcc -Wall -o ex9-1 ex9-1.c
ex9-1.c: In function 'main':
ex9-1.c:16:5: warning: implicit declaration of function 'selection_sort' [-Wimplicit-function-declaration]
ex9-1.c:20:2: warning: implicit declaration of function 'prinf' [-Wimplicit-function-declaration]
ex9-1.c: At top level:

[Code] ...

Compilation exited abnormally with code 1 at Sun Feb 10 20:14:49

Code:
#include <stdio.h>
int main(void) {
int a[100], i, j, N;
printf("How many numbers will you be entering: ");
scanf("%d", &N);

[Code] .....

View 4 Replies View Related

C++ :: Program Read In 15 Integers From User Then Store And Print Out Numbers

Apr 29, 2014

I want to write a program to read in 15 integers from the user, and then store them in a 5x3 array, and print out the numbers as a 3x5 array.

View 7 Replies View Related

C++ :: User Input 10 Integers Of Array - Add Numbers Greater Or Equal To 10

Oct 29, 2013

create a program that asks the user to input 10 integers of an array the program will add the numbers greater or equal to 10.

View 6 Replies View Related

C :: Using Arrays - Program That Prompts For And Reads In Test Scores

Feb 11, 2013

Write a program that prompts for and reads in test scores. You may assume that valid test scores will be integer values between 0 and 100. You may also assume that the user will not enter more than 35 test scores. Use a preprocessor directive to define this value. User input will be complete when the user enters a -1 for the test score. When all of the test scores have been entered, the program will print out the scores. Use a while or do-while loop to read in the values. Use a for loop to print out the values.

Sample output:
Enter test score 1: 88
Enter test score 2: 67
Enter test score 3: 74
Enter test score 4: 94
Enter test score 5: 79
Enter test score 6: 56
Enter test score 7: -1
Number of scores entered: 6
Test scores entered : 88 67 74 94 79 56

View 14 Replies View Related

C++ :: Read Set Of Integers Then Find And Print Sum Of Even And Odd Integers

Apr 21, 2014

I'm a beginner at c++ and I need to write a program that reads a set of integers and then finds and prints the sum of the even and odd integers. The program cannot tell the user how many integers to enter. I need to have separate totals for the even and odd numbers. what would I need to use so that I can read whatever number of values the user inputs and get the sum of even and odd?

View 2 Replies View Related

C++ :: For And Do While Loops

May 10, 2014

I this notation:
for (; *strings[i]; i++)

the same as:
do {
i++
} while(*strings[i]);

?

View 2 Replies View Related

C :: Integer Sum Using For And While Loops

Mar 6, 2015

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 () {

[Code] ....

View 12 Replies View Related

C :: Why Keep Getting Infinite Loops

May 30, 2014

See code below:

#include <stdlib.h>
#include <stdio.h>

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?

View 6 Replies View Related

C :: IF Statements Within Loops

Jan 29, 2014

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;
}

[code]....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved