C++ :: STL - Loop To Access Integers

Sep 17, 2013

I have to write a loop to access the integers. Then fill it with few sample data.

list<map<set<string>,int> l;

View 15 Replies


ADVERTISEMENT

C++ :: Terminate Loop When Two Integers Between 1 To 100 Are Equal

Mar 21, 2013

creating a program using while that terminates the loop when two intergers any two between 1 to 100 are equal with each other

View 2 Replies View Related

C/C++ :: Compute Sum And Average Of All Positive Integers Using Loop

Oct 8, 2014

I got an assignment which asked me to create a program that asks user to input 10 numbers (positive and negative) integer. The program would be using loop to compute sum and average of all positive integers, the sum and average of negative numbers and the sum and average of all the number entered. But, the new problem is after I've entered all the number, the answer that the program gave me wasn't the answer that the program supposed to give. I don't know how to describe it, I would attach a picture and the code below:

#include <iostream>
#include <cstdlib>
using namespace std;
int main() {
//Declaration
int x, value, sum, average, SumPositive, SumNegative, Positive, Negative;
float AveragePositive, AverageNegative;

[Code] .....

View 12 Replies View Related

C/C++ :: Program That Uses While Loop To Read A Set Of Integers From Input File?

Apr 20, 2014

The question is "Write a program that uses a while loop to read a set of integers from an input file called "data.txt" and prints the total number of even numbers read from the file."

Code below is the program I have created so far. I keep getting the window to pop up but not stay up so I am assuming I am doing something wrong.

#include <iostream>
#include <fstream>
using namespace std;
int main() {
std::fstream input("data.txt");
if (!input.is_open()) {
std::cout << "There was an error opening data.txt";

[Code]...

View 5 Replies View Related

C++ :: For Loop That Computes Total Of Certain Number Of Integers And Then Outputs Sum

Sep 30, 2014

I am trying to do a simple for loop that computes sum of a certain number of integers and then outputs the sum.

.text
.globlmain
main:
li $9, 0
li $10, 0
li $11, 10
li $12, 0
li $13, 0

[Code] ....

There error I keep getting is on the line with the branch

Instruction references undefined symbol at 0x0040003c [0x0040003c] 0x10200000 beq $1, $0, 0 [exit-0x00400038]

View 1 Replies View Related

C++ :: Access Private Data Of Base Class Without Access Modifier

Sep 9, 2013

if we don't provide the acces modifiers for base class and we need to manipulate the private data of base class in derived class. Is there anyway to acces the private data members? Here's a coding example

class A {
private :
int a;
};
class B : public class A {
public :
void displayA() { cout<<a<<endl; }
};

how i can acces the a of base class A in derived class B without acces modifiers.

View 16 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 :: Loop Does Not Work And Program Quits Without Displaying For Loop Function

Oct 13, 2014

We are making a program--but every time we input a value for scanf, the following for loop does not work and the program quits without displaying the for loop's function. We are not getting any errors.

View 11 Replies View Related

C# :: Use Loop To Load Two Forms Back And Forth Then Stop At Loop 4

Feb 15, 2015

I have tried to submit this topic before but i didn't submit my whole code and it was removed. So here it is. All I am trying to do is load form2 from form1 then back to form1 from form2 for a certain number of times the get out of the loop. I am new to C-Sharp and it seems as though I cant seem to figure out a way to do this.

Here is form1 and form2 code. I have commented out a few things I have tried.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;

[Code]....

View 3 Replies View Related

C :: Extra Loop Being Executed In Do-while Loop

Jul 1, 2013

Code:
#include <stdio.h>
#include<ctype.h>
void try5t(){

char choice;
int choiceint;

[Code] .....

Loop is repeated an additional time as shown in the screenshot:

View 9 Replies View Related

C/C++ :: Sum Of First N Integers

Oct 5, 2014

Write a program, sumit.c, that reads an integer value n from the user and then sums the integers between 0 and n. Your program should be able to handle both positive and negative values of n and should write the sum to the output file sumitout.txt. Note that your sum should not actually include 0, since that doesn't affect the sum. Your program should open the file sumitout.txt for appending so that the file can record a series of runs.

For marking purposes run your program twice with values n = −10 and n = 5.

Here is a sample run:

Enter n: -4 The sum of integers from -1 to -4 is -1

#include<stdio.h>
int main(void) {
//declare your variables
int n, i, term, total = 0;
//promt user to enter and read a value of n
printf("Enter n: ");
scanf("%d", &n);
//calculate the sum

[Code] ....

View 2 Replies View Related

C :: Dividing Two Integers

May 14, 2014

i am relatively new to C programming so i run into problems on daily basis. But this time i have something i just cant figuer out and i was hoping you could point me towards the right track. I am trying to divide two integers.DevValue by KpTotal. for some reason my micro controller allways crashes.Y is a variable of a distance measuring sensor. i have a 4x4 keypad to enter a three digit number (e.i 123) so Kp1 = 1 Kp2 = 2 Kp3 =3.

Code:

int kp1, kp2, kp3, kpTotal = 0;
char txt[6] = ""
int keypadPort at PORTD;
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
}

[code]....

i think it has something to do with the format of the value. i read that the micro controller crash when dividing by zero.

View 1 Replies View Related

C++ :: How To Get Larger 2 Out Of 3 Integers

Mar 12, 2014

How to write a simple function that will take 3 ints and find the sum of the higher 2? This is what i got so far:

int findsum(int a,int b,int c)// will find the highest int and return it to our main program {
int max,max2;// this sets our local variable max
// next we will find the larger of our first 2 variables
if( a>=b)
{ max=a;

[Code] ....

How to get the second highest number and add it to max

View 19 Replies View Related

C++ :: Subtraction Of Two Integers?

Apr 18, 2014

I am working on an assignment where I have to subtract two very large integers. How can I write it's code provided that I have both numbers in a character array with each index holding a fraction of the original number. Like if I have a number 123456789 in an array then

arr[0]='1';
arr[1]='2';
arr[2]='3';
arr[3]='4';
and so on. n

nNw if i have to subtract this number from an other number, how can I do that?

View 4 Replies View Related

C++ :: Link The Strings To The Integers?

Nov 8, 2014

Code:
#include <iostream>
#include <string>
using namespace std;
int main()

[Code] ......

How do I link the strings to the integers?

View 4 Replies View Related

C++ :: Random Integers (numbers)

Oct 17, 2014

I'm trying to make a C++ program that generate 6 random numbers ( from 100,000 to 999,999 ), okay, so I wrote a few lines..

Code:
srand(time(0));
for (int i = 0; i < 5; i++)
{
std::cout << 100000 + (rand() % 999999) << std::endl;
}

The problem is, that it generates numbers like this:

117,207
123,303
131,083
... etc etc..

They're all starts with 100K, i want them to be an actual random..

View 8 Replies View Related

C :: Reading Integers That Are In A String?

Dec 3, 2013

I am doing a program and i need to read integers that are in a string and i dont know if i am doing it correctly.

Code:
unsigned int j=0, h1;
char num[100] , str1[100], str2[100], a[100], b[100];

sscanf(str1, "%[^;] ; %[^;] ; %d ", a, b, &h1); the string is : "0048915433190;24/10/2013;13h 7m 47s;13h 8m 59s;0;1;"

And what i want to read with sscanf is the hours, minutes and seconds.

View 1 Replies View Related

C :: Integers Are Not Passed Through Functions

Nov 12, 2013

I am trying to create a program that reads my file filled with random words, it then compares the words after they are put into a 2d array and sees if there is any matching words.. unfortunately the count is not working for me (in function2 and function3) and I am not sure why..

Code:

#include<stdio.h>
#include<string.h>
char function1(char words_array[][17]);
int function2(char words_array[][17]);
void function3(int pairs, char words_array[][17]);
int main( void )
{ char words_array[20][17];
int x = 0;

[Code]...

View 6 Replies View Related

C :: How To Concatenate Two Integers Into One Integer

Oct 15, 2014

How i can concatenate two integers into one integer. I have code that concatenate two integers but if the 2nd integer is zero it won't work. How can i modify it so that it can cater the case of y=0 too.

Code:

int concatenate(int x, int y) {
int pow = 10;
while(y >= pow)
pow *= 10;
return x * pow + y;
}

View 12 Replies View Related

C :: Program Using A Function To Add Two Integers

Dec 2, 2014

I compiled a simple program using a function to add two integers, in order to understand the difference of calling by value vs by reference.

Code:

#include <stdio.h>
int add(int a, int b, int sum);
int main()
{
int a, b, sum;
printf("Please enter two integers
");
scanf("%d%d", &a, &b);

[Code]...

I used these two (one, two) pages I found in the net while studying the subject. So here are my questions...

(a) Do I understand correctly that in the above code all a, b and sum are passed by value?
(b) If I wanted only sum to be passed by reference, how the above code would change?
(c) If I wanted all (a, b, sum) to be passed by reference, how the above code would change?

View 12 Replies View Related

C :: Average And Total Of Six Integers

Jan 22, 2013

"Write a program that prompts the user for an integer number from the keyboard, and store it in a variable num. After each number is typed in, add num to a total.

Do this six times, each time adding num to a total. (Be sure to reuse the same variable named num for each of the six numbers entered.) When all six numbers have been entered from the keyboard, calculate an average. Display the total and average calculated. "

Here is what I have so far:

Code:
#include<stdio.h>
int main() {
int num, total1, total2, total3, total4, total5, total6, avg;

printf("Enter first number:");
scanf("%2d",&num);

[Code] .....

View 2 Replies View Related

C :: Functions Retuning Non Integers

Apr 5, 2013

from k&r book (4.2 - functions retuning non integers)
(doesnt compile - 1 error)

Code:

#include <stdio.h>
#define MAXLINE 100
/* rudimentary calculator */
main()
{
double sum, atof(char []);
char line[MAXLINE];
int getline(char line[], int max);
sum = 0;
while (getline(line, MAXLINE) > 0)
printf(" %g
", sum += atof(line));
return 0;
}

Code:

int getline(char line[], int max); is no different from:

Code:

getline(char line[], int max); ?

so, the int (return type) is optional when using a function. i assume return type is casted double? why the (char [])? just weird cuz i never seen it before

View 2 Replies View Related

C :: Comparing Pointer And Integers?

Mar 25, 2013

I am trying to make a game where you have a secret code that is coded with colors like ROYG (red,orange,yellow,green) and I am having trouble when it tells you when you have a right color in the right spot or a right color in the wrong spot when you guess a color. How can I change my code under the function int comparearray where it will compare pointers to pointers and not integers and give me the correct number of "almost" and "correct".

Code:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define ROWS 100
#define COLS 4
}

[code]....

View 4 Replies View Related

C++ :: How To Do Operation Of Two Integers That Gives Results

Feb 25, 2014

How do I do the operation of two integers that gives you the results?

I'm supposed to write a program that:

Asks the user for an integer
Asks the user for one of '+', '-', '*', or '/' (as a character)
Asks the user for another integer
Performs the given operation on the two integers, and prints out the result of

Please enter an integer: 4
Please enter an operation (+, - , *, /): *
Please enter another integer: 5

4 * 5 = 20

Code:
#include <iostream>
using namespace std;
int main() {
int x;
int c;
int d;
char e;

[Code] ....

View 7 Replies View Related

C++ :: Vector With Strings And Integers

Apr 5, 2013

I have a file where the first column shows letters, second column shows numbers.

How could I make it to print everything exactly how it is in the file – a vector/array with strings and integers?

View 13 Replies View Related

C++ :: Characters With Integers Tabbed To Right?

Oct 2, 2014

I took a month's break from programming, and got rusty. Here's the problem:

The character 'b' is char('a'+1), 'c' is char('a'+2), etc. Use a loop to write out a table of characters with their corresponding integer values:

a (tab) 97
b (tab) 98
...
z (tab) 122

View 2 Replies View Related







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