C++ :: Passing / Returning Character And Integer Arrays With Functions
Jun 21, 2013Passing and returning character and integer arrays with functions using simple programs...use pointers if necessary
View 1 RepliesPassing and returning character and integer arrays with functions using simple programs...use pointers if necessary
View 1 Replies i have a program that works, but now I am trying to get function1() to work. What it has to do is bring in the array and populate it with random letters. I don't know much about functions.
Code:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#define maxrow 20 //defines maxrow as a constant of 20
#define maxcol 30 //defines maxcol as a constant of 30
}
[code]....
Description: Use functions and structures to simulate storage in a warehouse
*/
#include <cstdlib>
#include<iostream>
#include<cmath>
#include<iomanip>
#include<string>
using namespace std;
struct Bin {std::string name; int Quantity;}; //create a structure for "Bin"
[code].....
I keep getting a linker error on every function. what am I doing wrong?
I'm having trouble with passing a character array between functions of the same class. I have a function, buildGraph, that calls function getNextLine. The getNextLine essentially just retrieves the next line of an input file and stores it into a "char line[80]". However when I try to use "line" in my buildGraph function, it has nothing in it.
Here's my code:
Class
#define NUMNODES 10
using namespace std;
#pragma once
class Prog3Graph
[Code] ....
we were given this code:
// Music Shuffle Program
// This program takes an array of strings and randomly permutes their order.
// This allows us to generate new song shuffles.
#include <iostream>
[Code]....
or are they referring to something else?
why the function is not returning the integer 1 or 0 ... We have two arrays A and B, each of 10 integers. Write a function that tests if every element of array A is equal to its corresponding element in array B. The function is to return true (1) if all elements are equal and false (0) if at least one element is not equal.*/
#include <stdio.h>
#include <iostream>
#include <time.h>
using namespace std;
int TEST (int arrayA[], int arrayB[], int j);
int main() {
srand (time(NULL));
[code].....
I have an assignment in my C++ class that is to create a menu based coffee shop program. Here is what I have so far:
#include<iostream>
#include<cmath> //doubt this is needed but i added it just in case
using namespace std;
[Code]....
I'm working on what I thought was a pretty simple program. I'm writing a menu driven program that will allow users to obtain specified measurements of several geometric figures. I was trying to test each each time I add a function.
I keep getting this error. error C3861: 'AreaOfSquare': identifier not found.
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
int menu() {
int choice;
[Code] ....
I wrote this code for a homework assignment, everything runs fine but the function void percent_votes (line 66) isn't calculating properly, it outputs 0.00 for each value. I have tried everything I can think of to try and make it work.
Here is the assignment: Write a program that allows the user to enter the last names of five candidates in a local election and the number of votes received by each candidate. The program should then output each candidate's name, the number of votes received, and the percentage of the total votes received by the candidate. Your program should also output the winner of the election.
Here is the code I have written:
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
[Code].....
After compiling, I cannot understand why my getMost and getLeast functions are returning erroneous values. I've done everything I could think of to try and fix this, Problem and code below.
A local zoo wants to keep track of how many pounds of food each of its three monkeys eats each day during a typical week. Write a program that stores this information in a twodimensional 3 * 7 array, where each row represents a different monkey and each column represents a different day of the week. The program should rst have the user input the data for each monkey. Then it should create a report that includes the following information:
* Average amount of food eaten per day by the whole family of monkeys.
* The least amount of food eaten during the week by any one monkey.
* The greatest amount of food eaten during the week by any one monkey.
Input Validation: Do not accept negative numbers for pounds of food eaten.
Code:
#include <iostream>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
// Constants.
const int NUM_MONKEYS = 3;
const int NUM_DAYS = 7;
[Code] ....
#include <iostream>
using namespace std;
int main(){
int x;
cout << "Enter character:";
cin >> x;
[Code] ....
If i type in:
+
How come it says that "this is not addition?
This is my c++ code...the problem is the RESULT is not coming and a bigger number is outputting...I dont know how to convert character to integer..
Code:
#include <iostream>
#include <math.h>
#include <stdlib.h>
using namespace std;
const int size = 50;
char infix[size],postfix[size],stack[size],dummy='?';
int top=-1;
[Code]....
how to carry out the conversions. The assignment is the normal hex to octal and Quart (base 4) via bit munipulation which I have worked out myself. However, I have been trying all day to figure out how to read in a string such as H1234, or O4567. How to parse the input I can handle the remainder myself. I'm just stuck and I've tried for hours.
View 5 Replies View RelatedI wrote this code purely for educational purposes. It also learn more about how exactly things look in memory. code I have right now ( I will likely add more and change it in the future) .....
Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
[Code].....
Im trying to swap the values of an integer and a character, however Im not sure where to insert the static_cast<type> part that I need for this to happen?
// Program to demonstrate a function template
#include <iostream>
using namespace std;
// Interchanges the values of variable1 and variable2
template<class T>
void swap_values(T& variable1, T& variable2)
[Code] ....
I have been trying to write a function which can convert a number from an unsigned long integer to a readable ASCII character string. this is what I have come up with, but I am receiving some very strange characters in return. Could the problem be that I am telling a char to = an unsigned long int, (cString[i] = product[i])?
void convertToString(unsigned long con) {
unsigned long product[10];
char cString[10];
const unsigned long begConvert = 10 ^ 10;
[Code] ....
all i want to do is to read a fixed char array sized 4 from user and pass it to Binary File then Print Encrypted content from the the File to the console screen .. but it seems it prints the same input every time .. and i tried everything .. it works fine with integers and strings .. but when it come to char array nothing ..
#include <iostream>
#include <fstream>
#include <cstring>
using namespace std;
[Code].....
Here is my program to look up words. How do I use character pointers instead of using arrays?
Code:
#include <stdio.h>
struct entry
{
[Code].....
I'm trying to create Minesweeper and with 2D Multidimensional character Arrays, It doesnt appear like in a grid format i want it to.
#include<iostream>
#include<conio.h>
#include<string>
#include<cstdlib>
#include<ctime>
[Code]....
The function uses a "for" loop to print the given character the number of times specified by the integer.
How can I make a for loop to do that?
So.. my code looks like this:
// cpp : Defines the entry point for the console application
//
#include "stdafx.h"
#include <iostream>
using namespace std;
void printMyInteger(int myInteger, char myChar) {
[Code] ....
So.. here is my error:
Error1error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
Error2error C2143: syntax error : missing ';' before ')'d:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp101Week 6
3IntelliSense: expected an expressiond:workspaceuniversity ools for games and animationworkshopsweek 6week 6week 6week 6.cpp107Week 6
forget everything from before. It came out of confusion regard the supplier functions. dis_s() and read_s() the part functions work and are not any different really.
Code:
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define MPS 10 //Max Part Size
#define MSS 10 //Max Supplier Size
}
[code]....
when I run the dis_s() function it just prints out garbage until it segments. starts with a bunch of 0 and newlines until it starts printing locations on my computer...... it worked on campus with debian and I only copied it from gmail to my computer so I really don't understand whats up(im on mint).
According to [URL] ....
" char myword[] = { 'H', 'e', 'l', 'l', 'o', '