C++ :: The Max Of N Inputs That Is Divisible By 3
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
ADVERTISEMENT
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
Apr 28, 2012
How to write a program of odd numbers divisible by n
View 1 Replies
View Related
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
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
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
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
View Related
Dec 7, 2014
I have learnt recently how to use fgetc, fputc, fputs, fgets but still I am not able to figure out how to read values from a file like for example:
12 14 1928 32993932
17 98
166 109 201
These are separate integers & i want to read them and then manipulate these individual integers like going for 2*I1, 4*I2 and so on where I1 and I2 are 12 & 14.
View 2 Replies
View Related
Apr 9, 2014
I want to have calculations take place inside a switch statement that calls the appropriate function. The menu portion of the program works well, but I can't figure out how to let the user actually input 2 different numbers to the functions. My questions are:
1. If I use scanf to assign values to the variables, what determines end of input to each variable? (ie.. scanf("%d%d", &a, &b) what is the end of a, what is the end of b?)
2. Should I assign the variables to user input inside the switch, or try to do it in the functions below?
3. Is there something I haven't thought to ask that will screw me over? I'm really new to this.
Code:
#include<stdio.h>
int add(int b, int a);
int mult(int b, int a);
main() {
[Code] ....
This really was a test of multilayer menu, but I want to add functionality if I can.
Changed a variable before posting and didn't change all the conditions testing it.
View 3 Replies
View Related
Sep 27, 2013
On my program I use a counter to count to 10, then i ask for a string, in this case "yes" or "no", during the count, i want to keep the user from putting inputs in, due to the fact that if they put both "yes" and "no" before the program reads the string.
Code:
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <stdbool.h>
#include <time.h>
#include <string.h>
}
[code]....
View 3 Replies
View Related
Mar 2, 2014
it skips the input phase,, instead of inputting the last name it goes directly to the firstname then middle initail and street name are working fine but it skips the street name then goes to city and so on....
Code:
char l[50], f[50], m;char strtname[50], cty[50], cntry[50];
int strtnum, zp, i;
system("cls");
printf("Enter Last name:");
gets(l);
printf("
Enter First name:");
}
[code]....
View 3 Replies
View Related
Jul 23, 2014
I have a project that requires I take user input from menu options and put it into an array which I will average out. I can set the menu up I think, but I cannot understand how to put what the user inputs into an array. Granted I just took the lecture on arrays today. Also we can only use functions to do the work.
View 9 Replies
View Related
Nov 23, 2014
I don't know how many numbers will be the input only that its going to be up to 10000. EOF should be active. I tried it like this:
Code:
int i = 0;
int del[10000]
while (scanf("%d",del[i])!=EOF)
{
i++;
}
But it seems the value of i doesn't increment, could you provide some tips on how to scanf the inputs into an array if I don't know how many numbers will I have?
View 7 Replies
View Related
Oct 26, 2013
Any chances for a c program to check for browser inputs?
View 1 Replies
View Related
Feb 14, 2013
For a program I am required to use a cin that accepts 4 variables. The first describes a function such as add(), remove(), print(), or quit(). The problem is that to use add() I need to input all 4 variables but for remove(), only 2 variable input is needed.
I want the input to be "add 9 James Bond"
or be "remove 341"
Here is my current code.
int command(string command, int Id, string first, string last){
while (command != "quit"){
cout << "customers> ";
cin >> command >> Id >> first >> last;
if (command == "add")
[Code] .....
View 1 Replies
View Related
Feb 10, 2013
I am new to C++ and I want to learn how to set color a particular color for the users input and output. For example, I want to display the users input as green, and their output as red.
View 2 Replies
View Related
Jul 19, 2013
How to combine the if statements?
cout<<"Enter a sale number"<<endl;
cin>>rec.sale;
if(cin.fail())
{
cout<<"Enter a number"<<endl;
cin>>rec.sale;
}
[Code]...
View 13 Replies
View Related
Feb 1, 2013
How to use library management inputs
View 2 Replies
View Related
Feb 23, 2013
Make a C++ Program that will use nested if else and any looping statement to display the following a certain number of times depending on how many times the user wants it to do so.
Input Values:
1. Name of employee
2. Position in the company
3. No. of hours worked
4. Rate per hour
5. Overtime hours
Required Output:
No. Name Position Rate per No. of hours Basic No. of overtime Overtime
hour worked Pay hours Pay
1. Juan Manager 160 140 22400 10 2100
Computations:
basic pay = no. hours worked x rate per hour
overtime = overtime hours x 150% of rate per hour
Just asking how can I input the name, position, rate per hour, overtime hours and hours worked in a horizontal manner?
Because I need to achieve the required output.
View 1 Replies
View Related
May 26, 2014
How to make an input with a string thats part of an if statement. How I think it should be done :
#include <iostream>
#include <string>
using namespace std;
int main() {
string choose;
[Code] .....
But I get a strange warning (not an error, but something that is like "just letting you know" i suppose) and when i enter in ss or SS or aa or AA, it breaks my app.
View 7 Replies
View Related
Mar 16, 2014
How to get user inputs into an array. I have to get 10 user inputs into the array and I'm trying to use a loop but once I run it it crashes whenever you input the first value. This is my absolute first time working with arrays and I've been trying to do research
#include <stdio.h>
#define SIZE 10
void Input(const int array1[]);
void Calculations(int array1[], int average);
void Output(int array1[], int average);
[Code]....
View 2 Replies
View Related
Oct 6, 2014
my lecture notes had this chunk of code on it. Which was the way to let a user enter not more than 40 different numbers , and save it into an array. The code is as follows :
#include <stdio.h>
#define MAX 41
void readData(int num[] , int * count);
[Code]...
In the function readData , why is n being scanned before and during the while loop?
View 1 Replies
View Related
Nov 26, 2013
It's not something trivial but I would like to know the best way to process multiple outputs, for example:
Input
First line of input will contain a number T = number of test cases. Following lines will contain a string each.
Output
For each string, print on a single line, "UNIQUE" - if the characters are all unique, else print "NOT UNIQUE"
Sample Input
3
DELHI
london
#include<iostream>
Sample Output
UNIQUE
NOT UNIQUE
NOT UNIQUE
So how can I accomplish outputs like that? My code so far is:
Code:
int main(int argc, char *argv[]) {
int inputs, count=0;
char str[100];
char *ptr;
scanf("%d",&inputs);
[Code] ....
But the above will obviously print the output after each input, so I want to know how can I achieve the result given in the problem. Also another thing I want to know is, I am using an array of 100 char, which it can hold a string up to 100 characters, but what do I have to do if I want to handle string with no limit? Just declaring char *str is no good, so what to do?
View 5 Replies
View Related
Jul 31, 2013
I have recently looked into a self created project where I wanted to compare user input against a list of strings in an external file. That has since been completed to my great satisfaction, however it did throw up some interesting issues in my knowledge and understanding of user input..What is the best way to pick up user input i.e scanf,stdin etc. and when should either be used and can a mixture of types be used, and if so, when and why.
A quick program to take different input methods and display differnt output method (obviously corresponding i.e scanf/printf - fgets/fputs)
My first pothole came when I have setup the method for scanf - fine. Then I setup the method for fgets(test,100,stdin) for example and the fgets method no longer picks up stdin from the user..
View 3 Replies
View Related
Jan 23, 2014
I am beginner at C and I was working on a program where I have to read in a line such as Digit, String, Float. The string can have any amount of spaces between it. and each input is separated by a space character.
The input is of the format:
10000000000 hello my n ame is 30.2
So I used fgets(x,100,stdin) to read the line in.
So I need to read that line into an int, array, and float.. so I was thinking of using this:
sscanf(x, "%d %[^/n] %f", &number, &username, &numberfloat);
Now, obviously I can't use the /n to read in the username with spaces because I need to read the 30.2 into a float variable.
View 5 Replies
View Related