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
ADVERTISEMENT
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
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 21, 2014
I have to write a program where the user will input integer numbers. How many numbers they enter is unknown, therefor you should use a repetition structure for the input. When the user is done, they will enter -1 to exit.
Create a dynamic array if the size=2( the initial size must be 2) Repeat until user enters -1.
I have to do this without using vectors.
This is what i have, I cannot figure out what to put in main. I was thinking of a do-while?
Code:
#include <iostream>
using namespace std;
void resize(int *[], int);
int main() {
int *listDyn;
int size=2;
[code].....
View 5 Replies
View Related
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
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
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
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
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
Jun 14, 2013
i'm trying to write a calculator. the user will enter the terms and they will be stored in arrays. i will be storing those terms in string arrays and then later turn them to double to work with them. but the user should be able to enter terms like sin(252) and the program should be able to recognize it and calculate it.
View 4 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
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
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
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
View Related
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
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
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 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
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
View Related
Jul 2, 2014
So I am trying to write a program that asks the user for a name. If the user enter the right name the program ends but if the user were to enter the wrong name the program would enter a loop prompting the user to re-enter the name. However I am not able to get the program to work!
View 9 Replies
View Related
Jan 28, 2013
So I'm trying to create a program that allows one to read/write on to output.txt. I though I had everything set up right, but its only writing one word to the text file. Heres the code.
#include "stdafx.h"
#include <iostream> //Needed for User Input
#include <fstream> //needed for ofstream
#include <string> // needed for strings
#include <windows.h> //needed for Sleep
#include <cstdlib> //Needed for return EXIT_SUCCESS;
using namespace std;
int main() {
ofstream outputfile; //allows to read and write to files
[Code] .....
If I type Puppies Are Cute and go to output.txt, the only thing written in the text file is Puppies.
View 9 Replies
View Related
Apr 18, 2014
I'm trying to write a program where it asks the user for a file name.
If that file exists, the it will open the file and then read it and print the information in the file.
However, if the user enters a file name that does not exist, the user will have 2 more tries (for a total of 3 tries) to get the correct name of the file.
I am close to getting it. What I have now just won't go through the loop to validate if the input matches an existing file. It goes straight to the printing of what is in the file. If the file doesn't exist, it prints: "Found your file..Opening..processing...Total keys found = 0."
So, my question, what am I doing wrong that it won't go through the loop properly?
#include<iostream>
#include<iomanip>
#include<fstream>
#include<string>
using namespace std;
int main() {
bool fileFound = false;
[code]....
View 2 Replies
View Related
Apr 20, 2014
I'm new to coding, and I have to write a program to display a class schedule to the user (the classes are entered into the program in strings like this:
Code:
course Calculus3 = {80934,"MATH",11,"Calculus 3","Edward Turner","M,W",950,1100}; )
in the format of an excel file (the user picks the classes they want to have) that then displays the course title and professor in the correct cell corresponding to the day/time the class meets. I've been googling it, and from what I've read, I think I need to use a csv file, but I don't know how to input the data into the file. I know the general format for how data is entered, but I don't know how to write it into a specific file or if I even have to (we covered txt files very briefly in my class, but never touched csv files).
View 3 Replies
View Related
Sep 22, 2013
I need to write a program to make the user input some text, and the first letter of each word has to be uppercase. (have to use while loops)
So for example lets say the user inputs:
i lOvE pRoGrAmMiNg
The output needs to be:
I Love Programming
Code: int main()
{
char c, lower_c;
printf("Enter Text");
while (c != '' && c >= 0)
{
if (c >= 'A' && c <= 'Z')
lower_c = c + 32;
else
lower_c = c;
[Code]...
I have started this code by making the letters lowercase (I don't know if this was the right way to approach this, ). I am not sure how proceed after this step, the step of making the first letter uppercase. (PS for the program, loops should be while loops)
View 6 Replies
View Related