C++ :: STL - Loop To Access Integers
Sep 17, 2013I have to write a loop to access the integers. Then fill it with few sample data.
list<map<set<string>,int> l;
I have to write a loop to access the integers. Then fill it with few sample data.
list<map<set<string>,int> l;
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 RelatedI 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] .....
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]...
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]
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.
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 RelatedWe 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 RelatedI 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]....
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:
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] ....
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.
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
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?
Code:
#include <iostream>
#include <string>
using namespace std;
int main()
[Code] ......
How do I link the strings to the integers?
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..
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.
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]...
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;
}
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?
"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] .....
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
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]....
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] ....
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?
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