I need help/aid on my c++ program/file. I am a beginner and I am using the code that I saw on youtube, but a bit different. The compiler does not detect any errors, however when the program runs, the void calc does not appear. Does anyone knows the program.
#include <iostream>
#include <cstdio>
#include <windows.h>
usingnamespace std;
void calc() {
int a;
int b;
int sum;
cout <<"Enter a number \n";
cin >> a;
cout <<"Enter the second number \n";
cin >> b;
sum=a+b;
cout <<"The sum of "<<a <<"+" <<b;
cout <<"=" <<sum;
Sleep (500);
}
int main() {
cout << "Hello World!" <<endl;
Sleep (1000);
cout << "Input your name: ";
string name;
cin >> name;
cout <<"Hello " << name <<" welcome to my C++ program " <<endl;
Sleep (1000);
cout <<"Random Number Generator" <<endl;
int numrand;
numrand+rand();
cout <<numrand <<endl;
cout <<"Enter the amount of hours you worked this week: \n";
int hours;
cin >> hours;
double totalpaycheck=hours * 10.15;
cout <<"You will recieve: " << totalpaycheck <<endl;
Sleep (1000);
int answer;
int a=5;
int b=6;
Sleep (1000);
answer= a+b;
cout << "5+6=" <<answer << endl;
Sleep (500);
}
Yea, you never called the function. It might be a good idea to capitalize Function names to make them standout from variable names which are preferred using the camel-casing format.
// function (capitalized)
void CalculatePay( );
// variable (camel-case)
int calculatedPay;
These are just conventions but they do make your code easier to read.
Thanks for the tips, I figure out the problem. As kapo pointed I did not declare the function in the main() function.
I found it weird that when I called/declare the function in last line of int main function but I didn't wrote void Calc();, but instead I wrote Calc(); and it works. However, when I tried to add void Calc();, the void Calc function did not appear. I appreciate your help kapo and IceThatJaw.