C/C++ :: Program That Outputs Numbers Divisible By Two Values
May 2, 2012
A program that outputs all numbers divisible by both 5 and 6.This is what i have written :
#include<stdio.h>
int main () {
int i=200;
int b=10;
while(i<1000)
i b/6%==0
}
where could i have gone wrong.
View 1 Replies
ADVERTISEMENT
Oct 2, 2013
#include <iostream>
using namespace std;
int main() {
int i=0;
while (i<=100) {
[Code] .....
the part where i need to check for values divisible by 5 is incomplete.
View 2 Replies
View Related
Apr 28, 2012
How to write a program of odd numbers divisible by n
View 1 Replies
View Related
Mar 1, 2013
I've pretty much finished the entire program, except for the actual calculation part.
"Given a range of values determine how many integers within that range, including the end points, are multiples of a third value entered by the user. The user should be permitted to enter as many of these third values as desired and your output will be the sum of total multiples found."
I've defined functions to take user input for the low range, high range and a do-while loop to take as many third inputs as the user wants (terminated by entering -1, as requested by the question)
To actually calculate if they're divisible, I found out that if A%B = 0, then they are divisible, so I thought I would create a loop where each value in the range between A and B is checked against the third value to see if they output a zero.
What I need to end up with is a program that tells the user how many integers are divisible by the numbers in the range, i.e: "Enter the low range value: 335 Enter the high range value: 475 Enter a value to check within the range: 17 Enter a value to check within the range: -1 There are 8 total values that are divisible by the numbers in the range." Going back to my original question, how would I create a loop or something to "check" how many values are equal to zero, and consequently increment a variable for each instance? (This is how I think it should be done)
Code:
#include <stdio.h>
//GLOBAL DECLARATIONS
int getlowR();
int gethighR(int);
[Code].....
View 4 Replies
View Related
Nov 18, 2013
I have been asked to write a program to grade several multiple-choice exams. The exam has less than 80 questions, each answered with a letter in the range of ‘a’ through ‘f’. The data are stored on several files such as exam1.dat where the first line is the key, consisting of a string of n characters (0<n < 80). The remaining lines on the file are exam answers, and consist of a student ID number, a space, and a string of n characters.
The program should have a while loop in the main routine to ask users input a data file name through keyboard. In this way, the program has a capability of repeatedly asking for a new data file in each while loop until users input a key word “exit”. Once “exit” is encountered, the while loop terminates and your program ends. A typical input exam data file (exam1.dat) looks like:
abcdefabcdefabcdefab
1234567 abcdefabcdefabcdefab
9876543 abddefbbbdefcbcdefac
5554446 abcdefabcdefabcdef
4445556 abcdefabcdefabcdefabcd
Apply strlen( ) or the length( ) of string to the first line of the above data file for determining the number of questions in the problem. If a student gives more answers than necessary, the extra answers will be automatically truncated. On the other hand, if a student provides less number of answers, the remaining unanswered questions are considered as being answered wrongly.
After users input an exam data file, your program should ask users to input another grade-curving file name (e.g., gradeCurving.dat). This second file contains the information to convert a percentile score to a curved grade in levels of ‘A’ through ‘E’. For instance, a grade-curving file takes the following format: a curved alphabetic grade, a space, a percentile grade served as marker.
A 90
B 80
C 70
D 60
E 50
The above information means that ‘A’ = 90 through 100; ‘B’=80 through 89; ‘C’=70 through 79; ‘D’ = 60 through 69; “E”=50 through 59; For the remaining grades, you can assign an ‘F’.
Furthermore, in each while loop in the main routine, your program should ask users to input an output file name such as score1.dat. The output file will store the scores for each student in a format: student ID number, a space, a percentile score, and a curved grade in ‘A’ though ‘E’. The program should also compute and display the following statistics for the graded answers: Average score, Maximum score, and Minimum score.
A typical output on a data file looks like:
1234567 90% A
9876543 85% B
5554446 95% A
4445556 75% C
5551112 80% B
Statistics:
Average Score: 85%
Minimum Score: 95%
Maximum Score: 75%
This Is what I have so far. It compiles fine and everything but when I input the files it says "There was an error opening the corresponding files. Check input name perhaps?" and it exits out ....
#include "stdafx.h"
#include <iostream>
#include <string>
#include <fstream>
#include <assert.h>
using namespace std;
int openfiles(ifstream& infile, ifstream& curvingfile, ofstream& outfile);
void Size(ofstream&,int,string);
[Code] ....
View 11 Replies
View Related
Mar 22, 2013
The program works, other than if I place the cursor below the last line in my merch file, the program outputs a line of garbage. The only solution I could find is to leave the cursor on the last line.
Code:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
struct vRecord {
string venue, item;
float price;
[Code]...
View 2 Replies
View Related
Jun 3, 2013
I need to write a program that outputs the number of characters, words, and lines in the files that are supplied as command-line arguments.
#include <iostream>
#include <string>
#include <iomanip>
[Code]....
View 2 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
May 6, 2014
I need to do a code that gave me Original string, uppercase string, lowercase string, reverse string (if letter is upper then convert to lower, and if lower then convert it to upper) and uppercase first (first character of each word in uppercase).
I need to do it in functions but i dont know hot to use strings. The program should provide the option to save the outputs in a file.
View 4 Replies
View Related
Sep 30, 2013
For class I need to write a program that inputs a file (the dividend), performs binary division on the file (using 0x12 as the divisor), and outputs the remainder(checksum).
I have researched binary division algorithms and I get the general gist, but I'm still unsure where to start. How would I store the dividend and divisor? As two arrays of bits?
Then, I need to figure out how to perform shifts and XORs on the the binary numbers. Maybe I should use bitwise operations?
View 5 Replies
View Related
Jun 15, 2013
I seem to be missing a concept or 2 here ... I am tasked with writing a program that reads text from a file and outputs each line to the screen as well as to another file PRECEDED by a line number ...
In addition, I have to Print the line number at the start of the line and right-adjusted in a field of 3 spaces ...
Follow the line number with a colon then 1 space, then the text of the line.
Another kicker, is I have to grab the data 1 character at a time and write code to ignore leading blanks on each line.
Here is what I have so far:
#include <iostream>
#include <conio.h>
#include <fstream>
#include <string>
#include <cstdlib>
#include <cctype>
using namespace std;
int main() {
char next;
int count = 0;
[Code] ....
View 7 Replies
View Related
Nov 29, 2013
Code:
#include <stdio.h>
int main(){
int A, B;
char decision;
printf("Do you have an integer to input? [Y/N]: ");
scanf("%c",&decision);
if(decision=='Y' || decision=='y'){
[Code]....
After entering a single integer, it doesn't scan again for another integer. What's wrong?
I'm using a mac btw, if that makes a difference with Ubuntu/Linux.
View 8 Replies
View Related
Mar 25, 2014
Does this program solve the problem of testing an integer to be divisible by 6?
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Chapter7Problem5
[Code] ....
View 2 Replies
View Related
Oct 2, 2014
Write a program that displays all the numbers from 100 to 1,000, ten per line, that are divisible by 5 and 6. Numbers are separated by exactly one space.
#include <iostream>
#include <stdlib.h>
using namespace std;
[Code]....
View 8 Replies
View Related
Mar 17, 2013
i am beginner in c++ , i need to write a programm that out ouputs a calender for a month when given a month and year using this frame work :
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;
[code].....
View 8 Replies
View Related
Apr 4, 2015
This program must take user input(from stdin) that contains both a number and then a punctuation character, either a single quote(') or double quote(") that specifies feet or inches. It keeps prompting the user to enter a length until the user enters the sentinel value of 0. For example:
Enter a measurement and unit: 1'
Enter a measurement and unit: 2"
Enter a measurement and unit: 0
Total: 14 inches
The ultimate goal of this program is to then write an Assembly language program that is structurally similar and makes use of these 4 functions:
void printStr(char *)
Arguments:
edi = address of null-terminated string to print
Returns:
Nothing
[Code] ...
So here is what I have:
int main() {
char value[50];
char *end;
int sum = 0;
long conv;
while(conv !=0)
[Code] .....
I was told to use fgets instead of scanf for for stdin to parse the number and the quotation marks. I think I converted the number from string to integer correctly with strtol, but I really do not know how to obtain the (") or (') from user input so the program knows whether to convert the number to feet or just inches. No matter what I type in, even if it's without a quotation mark, it still multiplies the number by 12. In the IF and ELSE IF statement, it should state
if(value = ''')
and...
else if(value = '"')
View 4 Replies
View Related
May 3, 2014
Assume you want to make sure that the user enters a positive number that is divisible by 10 with no remainder. Write the condition you would use in the following do-while loop.
do {
cout << “Enter a positive number that is divisible by 10 with no remainder” << endl;
cin >> number;
}
while ( ____________________________________________________________);
View 2 Replies
View Related
Dec 4, 2013
This is my code: [tag]
Code:
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
[Code] .....
View 4 Replies
View Related
Oct 22, 2013
Find the perfect numbers between a starting value and a finishing value entered by the users. Display the results to the screen.
I've been told that I need to modify things under the void and the calcdiv in my main () but I can't seem to figure it out. It needs display the perfect numbers between the starting and finishing value. e.g. 28 and 429.
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;
void calcdiv(int number) {
for (int i=1;i<=number/2;i++)
[Code] .....
View 3 Replies
View Related
Mar 14, 2013
srand (time(NULL));
for(int i=0; i<N; i++) {
points[i].x=(rand()%(32767-(-32767)))+(-32767);
points[i].y=(rand()%(32767-(-32767)))+(-32767);
cout<<"x="<<points[i].x<<endl;
cout<<"y="<<points[i].y<<endl;
}
Im trying to generate random numbers between -32767 and +32767, where im going wrong, this code generates only negative numbers
View 4 Replies
View Related
Jan 26, 2013
i did a code that determine if the number is prime or not, and i have to do a one that finding the prime numbers between two variables .
the first code:
#include<iostream>
using namespace std;
int main(){
[Code].....
View 4 Replies
View Related
Mar 16, 2013
I have 2 arrays, one of doubles and other of integers, the doubles have the result of division of two numbers and the array with the ints have numbers that will refer to another array, but it is not important for this problem.
An example:
doubles array: (12,44;12,44;7,22; 12,44)
ints array: ( 4 , 2 , 3 , 1 )
now using my quicksort function i will organize the array of doubles from the higher to the lower, and the ints array will follow the order of the doubles array, the result is :
doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 4 , 2 , 1 , 1 )
Well, when i have values in the doubles array that are equal, i need to check the ints array and order the ints values, but only the ints that in the doubles array are equals, the final result will be:
doubles array: (12,44;12,44;12,44; 7,22)
ints array: ( 1 , 2 , 4 , 1 )
How i can order the ints array only between an interval that is given by the interval of numbers that are equals in the doubles array?
View 4 Replies
View Related
Dec 2, 2014
The only part I have working is getting all odd random numbers but the logic in getting the largest and smallest from random is what is giving me alot of trouble.
class Program {
static void Main(string[] args){
int num = 0;
int largest = 0;
Random rand = new Random();
for (int ctr = 1; ctr <= 100; ctr++)
[code]....
Console.Write("{0,5} The larget number out of 100 odd numbers is: {1:n}",y,largest);
View 4 Replies
View Related
May 20, 2014
I want to make a program to print the product of even numbers between 1 and 30 and sum of odd numbers between 1 and 30. But the answer of product is negative. The photo shows the output of the code.
#include <stdio.h>
#include <conio.h>
void main ()
{
int i, even_product=1, odd_sum=0;
for(i=1;i<=30;i++) // For loop starts here!
[Code]...
View 5 Replies
View Related
May 16, 2013
I need to check my understanding from some questions about strings. How can numeric values stored as Strings be converted to numbers?
a)vector of required numeric data type
b)atoi function in cstdlib library
c)cout statement with required numeric data type
I picked b), I am aware of atoi, atol, and atof as methods to convert, but are there other methods?
What is the purpose of strncat function?
Combines n characters from source string into target string
C++ string provides:
a)convenient way to declare and manage character arrays
b)functions to manipulate strings
c)all of the above
d)none of the above
I picked c)
View 2 Replies
View Related
Jan 22, 2013
I want to finding maximum and minimum values of 10 numbers using for loop and the program work wrong !!
#include <iostream>
using namespace std;
int main() {
int x;
int max = -999999999;
int min= 999999999;
[Code] ....
View 2 Replies
View Related