Visual C++ :: Write A Program Where The User Will Input Integer Numbers?
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;
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,
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)
A program which takes input from user and write it to a file then it reads data from that file then it should search for specific data such as email adresses or url etc.
So I need to write a program which tells the user if the number they input is prime or not. I have done so and included the code below. My problem is that I need to allow the user to input if they want to enter another number after the first one using y or n and I am having trouble figure it out.
#include <cstdlib> #include <iostream> using namespace std;
I need to write a program that reads four float numbers from the input.txt file, then it prints out the greatest of the four numbers into the output.txt file. I did everything, but the numbers don't print out.
#include <iostream> #include <fstream> using namespace std; int main() { ifstream inFile; ofstream outFile; float number1, number2, number3, number4;
C programming: I want to creat a program that asks the user to input the integer lengths of three sides of a triangle, and if so whether the triangle is a right-angled, acute or obtuse one. i am having some doubts about the if, else if statements. I never seem to know how and in what order to use them.
Code:
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char *argv[]){ int SideA; int SideB; int SideC; }
#include <iostream> #include <string> #include <limits> //for std: numeric limits #include <algorithm> //Function to get an integer from the user that is greater than or equal to zero.
int getPositiveIntFromUser(const std::string& prompt) { int retVal = -1;
[Code] ....
The first part works, but it doesn't calculate the GCD or LCM at all, it just crashes!
I'm trying to create a program that will take input from a user and calculate it in a do-while loop. The program does the calculation but the answer is wrong. The loop also doesn't work. The purpose of the program is to see how much an item will cost after a discount is taken off and tax is added.
Write a program asks the user for a positive integer value and then prints out all perfect numbers from 1 to that positive integer. I have been trying for some time, i found a way to check if its a perfect number or not but could not find a way to prints out all perfect numbers from 1 to that positive integer. I am here so far.
#include<iostream> #include<iomanip> using namespace std; int main(){ int n,i=1,sum=0; cout<<"Enter a number: ";
As an assignment for school , I've to write a program to find the sum prime factors of a user input integer.
E.g. 20 = 2 x 2 x 5 , Sum = 2 + 2 + 5 = 9 E.g. 10 = 2 x 5 , Sum = 2 + 5 = 7
My method for finding the result is as follows :
- Divide the number by increasing values if int i , starting from i=2.
- Once I get a value of i that can divide the number without giving me a remainder , I add this value of i to int sum and divide the number by i.
- I will repeat this process until the user input value is equal to 1.
My code is as shown:
#include<stdio.h> int primecheck(int n); // Function to check if i is prime int primesum(int n); // Function to sum the values of i that are prime int main(void) { int n; int sum; printf("Enter a number (> 1): "); //Prompting and scanning user input ,n scanf("%d",&n); sum = primesum(n);
[Code] .....
But for some reason I keep getting an incorrect result, it's as if it is missing out the last factor for each case.
Eg. 20 = 2 x 2 x 5 , the result I get is 4 , which is 2+2 Eg. 40 = 2 x 2 x 2 x 5 , the result I get is 6 , which is 2+2+2;
i was trying to solve a problem in SPOJ and what i wanted to do is to accept an input number from the user and to convert it into a array of integer.
Code:
#include<stdio.h> int * toarray(int *num); int main(void) { int testCases; }
[code]....
But whenever i try to print the array in the main function i get only two value and the rest address
Code:
1//number of testCases 23456 //input number 6 2293452 4 2293700 1974439125
Process returned 0 (0x0) execution time : 4.152 s Press any key to continue. However, if i tried to print the array from within the function, it prints the numbers just fine.
print the array elements from the main program, so that i would be able to go on with the rest of it
I am trying to write code to find all the prime numbers before a user entered number. I started with a working program and when I tried to create a function, it got all messed up.
Code:
#include <stdio.h> int is_prime( int num ); int get_positive_integer(void); int main( ) { int upper; /* upper limit to check */ int num; /* current number to check */ int isprime; /* used to flag if number is prime or not */
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!
I have been trying to make a very simply programme that checks if the inputted information is an integer or not (i.e: that it contains no other characters).
I have tried using the isdigit function (but this only works for single characters). I have tried cin.clear, cin.ignore (1000) but this doesn't work either..
Any effective way to check if x in the following programme has been entered correctly
#include <iostream> using namespace std; int main() { cout << "Please enter an integer (positive or negative)" << endl; int x; cin >> x; HERE I WOULD LIKE CODE TO CHECK IF THE USERS INPUT IS VALID }
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.
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;
Now i got here a program that asks the user to input 2 numbers if the first inputed number is smaller than the second then show all even numbers from the range of the 1st inputed number till the 2nd inputed number, but if the first inputed number is greater than the second then display all odd numbers from the range of the 1st number till the 2nd.
now my question is how do i invert the odd numbers?(on the 2nd condition)
Code: #include<stdio.h> int main(void) { int i,a,b,x; printf("Enter two numbers"); printf(" First number:");
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:
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).
//Finding prime numbers #include <iostream> using namespace std;
[Code]....
/*The program currently prints all the prime numbers up to n (For example, if 7 is entered, it prints out: 1, 2, 3, 5, 7. What I want it to do, is print out the first 7 numbers; 1, 2, 3, 5, 7, 11, 13.
I am trying to write a program that adds numbers to an array. The array capacity starts out at 2, then doubles whenever the size reaches capacity. The program works perfectly fine when the array needs to be expanded. So I have narrowed down the issues into this one function (_dynArrSetCapacity)
Why this class doesn't work for Subtraction, Division and Square Root. When I try to get results for Subtraction, it output right answer, but with any trash. And When I try to get answer for Division and Square Root, it just brakes and don't output anything. For Addition and Multiplication class work correctly.