function was not declared in this scope - c++

#include <iostream>
#include <fstream>
using namespace std;
int information1(int hourR);
int information2(int conTime);
int intformation3(int income1);
int hourR,conTime,income1;
ofstream outfile;
int main()
{
int hours,consultTime,income,fortyPercent,seventyPercent;
outfile.open("Billing amount.txt");
hours=information1(hourR);
consultTime=information2(conTime);
income=information3(income1);
if((income<=25000)&&(consultTime<=30))
{
outfile<<"No charges";
}
else if((income>=25000)&&(consultTime>=30))
{
fortyPercent=hours*.4;
outfile<<fortyPercent;
}
if(consultTime<=20)
{
outfile<<"No charges";
}
else if(consultTime>20)
{
seventyPercent=hours*.7;
outfile<<seventyPercent;
}
outfile.close();
return 0;
}
int information1(int hourR)
{
cout<<"Enter hourly rate.";
cin>>hourR;
return hourR;
}
int information2(int conTime)
{
cout<<"Enter total consulting time";
cin>>conTime;
return conTime;
}
int intformation3(int income1)
{
cout<<"Enter income.";
cin>>income1;
return income1;
}
The compiler says information3 is not declared in this scope. But when I do declare it, the compiler says I cant use it. There might be more problems with this program but as of now I'm stuck on this part. Thanks for the help.

spot the difference
int intformation3(int income1);
^
income=information3(income1);

Related

c++ Process returned -1073741819 (0xC0000005)

Here is the whole code.
I know that the problem is somewhere in the hozzaad function, but I don't know to debug it.
I want to create a dynamic 2d array, with exacly vagonszam columns, but the number of rows differ.
#include <iostream>
#include <fstream>
#include <string.h>
#include <cstdlib>
using namespace std;
class Vonat{
int vagonszam, maxtomb;
int **vagonok;
int *seged;
enum szallitmany {szen, fa, ko} ;
public:
void beolvas(int x);
Vonat(): vagonszam(0), maxtomb(0) {}
void kiir();
void hozzaad(int **vagonok, int i, string szallitmany);
};
void Vonat::hozzaad(int **vagonok, int i, string szallitmany)
{
++vagonok[i][0];
seged = (int *) realloc(vagonok[i], ((vagonok[i][0]+1)*sizeof(int)));
seged[vagonok[i][0]]=1;
}
void Vonat::beolvas(int x)
{
char szovegesallomany[]="beVagonTartalma";
szovegesallomany[15]=x+'0';
szovegesallomany[16]='\0';
strcat(szovegesallomany, ".txt");
ifstream f(szovegesallomany);
f>>vagonszam>>maxtomb;
vagonok = new int*[vagonszam];
string szallitmany;
for(int i=0;i<vagonszam;i++)
{
vagonok[i] = new int[1];
vagonok[i][0]=0;
do
{
f>>szallitmany;
cout<<szallitmany<<" ";
hozzaad(vagonok, i, szallitmany);
}
while(szallitmany!="*");
}
f.close();
}
void Vonat::kiir()
{
cout<<vagonszam<<" "<<maxtomb<<endl;
}
int main()
{
Vonat v_52164;
v_52164.beolvas(1);
v_52164.kiir();
Vonat v_54587;
v_54587.beolvas(2);
v_54587.kiir();
return 0;
}
In this code something's wrong, because after running it gets the error message specified before.
Thanks to everyone, who try to help me, all the best.

friend function not printing out what it should

whenever I run the program, there is no output, the program just ends. Am i doing something wrong? I'm sure there's something i missed but i can't seem to figure it out.
#include <iostream>
#include <string>
using namespace std;
class Addr
{
public:
Addr(int i = 0){
total = i;
}
void addNum(int num){
total += num;
}
int getNum(){
return total; }
friend int print(Addr& var);
private:
int total;
};
int print(Addr& var){
return var.total;
}
int main()
{
Addr object1;
object1.addNum(3);
print(object1);
return 0;
}
Your program behaves correctly. There is no output because you are not printing anything to the console in your program.
The print function merely returns the total.
If you wish to print the value to the console then you could for example change the definition as follows:
int print(Addr& var){
cout << var.total << endl; // this prints to the console output
return var.total;
}
There is no issue with your code. The fact is that no print function is used. I have modified your main function.
int main()
{
Addr object1;
object1.addNum(3);
cout<<print(object1);
return 0;
}

Id returned 1 exit status. C++

I'm very new to C++, so I've probably made some really stupid mistakes. But I've looked online to solutions for this error, and I tried all I can think of.
I'm trying to have my whole program in one function, because it's going to be merged with other programs. The id error is the only error I have so far.
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
using namespace std;
int ninebooking(int Endor=0, int Naboo=0, int tatooine=0);
int sevenbooking(int Endor=0, int Naboo=0, int tatooine=0);
void BookingSystem(int time, int k);
int time;
int k = 0;
int main()
{
BookingSystem(time, k);
{
while (k==0)
{
printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
scanf("You have selected to book your meal for %d", &time);
if (time!=7||time!=9)
{
printf("Sorry, that was an incorrect time");
time = 0;
}
}
return 0;
}
system ("pause");
return 0;
}
Any help is much appreciated, I've spent a long time trying to fix this on my own with no luck.
Thank you!
You make many mistakes in your program:
1) You mix C & C++ syntax.
using namespace std, is C++
2) You include useless header files
3) You declare variables that I don't understand what for
Why do you need this?
int ninebooking(int Endor=0, int Naboo=0, int tatooine=0);
int sevenbooking(int Endor=0, int Naboo=0, int tatooine=0);
You don't use the variables above anywhere !!!!
4) You try to write a function inside main (this is not Pascal).
So, if I understand what you want, look at this:
#include <stdio.h>
void BookingSystem() // this is the function who does all job
{
int time = 0;
while ((time != 7) && (time != 9))
{
printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
printf("\nYou have selected to book your meal for ");
scanf("%d", &time); // read the time
scanf("%*[^\n]"); // consume all caracters until the newline
scanf("%*c"); // consume the newline
if (time == 7)
{
printf("You have selected to book your slot at 7PM\n");
}
else if (time == 9)
{
printf("You have selected to book your slot at 9PM\n");
}
else
{
printf("You have selected an incorrect time, please try again\n");
}
} // end while
} // end function
int main(int argc, char *argv[])
{
BookingSystem(); // this is the calling to your function
return 0;
}
If I understand what you want, this works fine.
you can not to Define Function in to the main ..
you must to do like this...
#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
using namespace std;
int ninebooking(int , int , int ); //just say data type int or ....
int sevenbooking(int , int , int );
void BookingSystem(int , int);
int main() //and in to main just call he...
{
int time;
int k = 0;
BookingSystem(time, k);//call ....and send parameter time and k
system ("PAUSE");
return 0;
}
void BookingSystem(int time,int k)
{
while (k==0)
{
printf("\n\nMeals are served at 9pm and 7pm, please enter what time you would like to book for");
scanf("You have selected to book your meal for %d", &time);
if (time!=7||time!=9)
{
printf("Sorry, that was an incorrect time");
time = 0;
}
}
// return 0;//if this function is void he can not to return any thing!!!!
}
int ninebooking(int Endor=0, int Naboo=0, int tatooine=0)
{
//......
}
int sevenbooking(int Endor=0, int Naboo=0, int tatooine=0)
{
//........
}

Prime numbers in an dynamic array

I've a program which inserts all prime numbers up to a specific number in an array.
The calculation is correct. My problems are the function parameters and the transfer of my dynamic array to the function. My function doesn't modify my array.
Please take a look at the code:
#include <iostream>
using namespace std;
int primeinlesen(int *i);
int primarrayspeicherung (int *primarray,int *bis);
int main()
{
int reload=1;
while(reload==1)
{
int bis=0,*primarray,valcounter;
primeinlesen(&bis);
valcounter=primarrayspeicherung(primarray,&bis);
for(int i=0;i<valcounter;i++)
{
cout<<i<<". Primzahl: "<<primarray[i]<<"\n";
}
delete [] primarray;
cout<<"Anzahl Primzahlen: "<<valcounter<<endl;
cout<<"Erneute Berechnung?(Ja(1) oder Nein(0))";
cin>>reload;
}
return 0;
}
int primeinlesen(int *i)
{
cout<<"Bis zu welchem Wert moechten SiePrimzahlen ausgegeben,haben(max.500)";
cin>>*i;
if(*i>500)
{
cout<<"Wert zu hoch...";
}
return 0;
}
int primarrayspeicherung (int *primarray,int *bis)
{
int x,y,counter,e,valcounter=0,xcounter=0,xvalcounter=0,xx,xy,xe;
for(x=2;x<*bis;x++)
{
counter=0;
for(y=2;y<x;y++)
{
e=x%y;
if(e==0)
{
counter++;
}
}
if(counter==0)
{
valcounter++;
}
}
//ZWEITER DURCHGANG
primarray=new int[valcounter];
for(xx=2;xx<*bis;xx++)
{
xcounter=0;
for(xy=2;xy<xx;xy++)
{
xe=xx%xy;
if(xe==0)
{
xcounter++;
}
}
if(xcounter==0)
{
primarray[xvalcounter]=xx;
xvalcounter++;
}
}
return valcounter;
}
Best regards
In this function:
int primarrayspeicherung (int *primarray,int *bis)
primarray is a local variable. Everything you're doing to it (e.g. allocating, assigning) only affects the local primarray, not the one you pass in. If you want to modify both, you need to pass in a reference:
int primarrayspeicherung (int*& primarray,int *bis)

C++ put data from stack to file

I still do not have much knowledge in C ++, I would like to ask for help for a task. I must create a stack, which is filled with data entered by the keyboard and the entire stack to write in external stack. I have made functions push, pop and simple program that displays the stack but before that data must be written in an external file. Can anybody help me with the external file?
#include <iostream>
#include <iomanip>
#include <stdlib.h>
using namespace std;
struct elem
{ int key; elem *next;} *start=NULL, *p;
void push(int n)
{
p=start;
start=new elem;
start->key=n;
start->next=p;}
int pop(int &n){
if (start)
{
n=start->key;
p=start;
start=start->next;
delete p;
return 1;
}
else
return 0;
}
int main(){
int num;
cout<<"Input integers:"<<setw(10);
while (cin>>num)
{
push(num);
}
cout<<endl<<"Stack:"<<endl;
while(pop(num))
{
cout<<num<<endl;
}
return 0;
}
//you can use this pseudocode
ofstream outFile;
while(start!=-1){
outFile << pop() << endl;