IDE that I'm using : Code::Blocks 16.01|Compiler that I'm using : MingGW GCC 6.3.0
Error(s):
Build Messages: v1 - Arrays\main.cpp|8|error: 'variableFlag' does not name a type|
My Objective(s): Want to set a global variable : variableFlag that's shared with all the *.CPP programs. I want to set it to a default setting of 0, or 1. If it's set to 0, I don't want to display the if statement in function : void print(int input) in mainLibrary.cpp. If it's set to 1, then display the if statement within the function.
mainLibrary.cpp
#include <iostream>
#include "mainLibrary.h"
#include <string>
using namespace std;
//int variableFlag;
//variableFlag = 0;
void asciiTable()
{
for (int id = 0; id < 256; id++)
{
char test = id;
cout << "ASCII CODE : " << id << " = " << test << endl;;
}
}
void dataTypesSize()
{
cout << "Size of char : " << sizeof(char) << endl;
cout << "Size of int : " << sizeof(int) << endl;
cout << "Size of short int : " << sizeof(short int) << endl;
cout << "Size of long int : " << sizeof(long int) << endl;
cout << "Size of float : " << sizeof(float) << endl;
cout << "Size of double : " << sizeof(double) << endl;
cout << "Size of wchar_t : " << sizeof(wchar_t) << endl;
}
void print(int input)
{
if (variableFlag==1)
{
cout << "\nprint(int input)" << endl;
}
cout << input << endl;
}
void print(long input)
{
// cout << "\nprint(long input)" << endl;
cout << input << endl;
}
void print(double input)
{
// cout << "\nprint(double input)" << endl;
cout << input << endl;
}
void print(const char* input)
{
// cout << "\nprint(char input)" << endl;
cout << input << endl;
}
void print(string input)
{
// cout << "\nprint(string input)" << endl;
cout << input << endl;
}
void printLine(const char* input)
{
cout << input;
}
void printLine(string input)
{
cout << input;
}
void printLine(double input)
{
cout << input;
}
void variableSwap(int &input1, int &input2)
{
int temp = input1;
input1 = input2;
input2 = temp;
}
void variableSwap(double &input1, double &input2)
{
double temp = input1;
input1 = input2;
input2 = temp;
}
void variableSwap(string &input1,string &input2)
{
string temp = input1;
input1 = input2;
input2 = temp;
}
mainLibrary.h
#include <iostream>
#include <string>
using namespace std;
#ifndef ASCIITABLE_H_INCLUDED
#define ASCIITABLE_H_INCLUDED
extern int variableFlag;
//int variableFlag;
void asciiTable();
void dataTypesSize();
void print(int input);
void print(long input);
void print(double input);
void print(const char* input);
void print(string input);
void printLine(double input);
void printLine(const char* input);
void printLine(string input);
void variableSwap(int &input1,int &input2);
void variableSwap(double &input1,double &input2);
void variableSwap(string &input1,string &input2);
#endif // ASCIITABLE_H_INCLUDED
main.cpp
#include <iostream>
#include "..\Library\mainLibrary.h"
#include <string>
using namespace std;
//int variableFlag;
variableFlag = 0;
int main()
{
asciiTable();
dataTypesSize();
string names[10]; //Initializes names array as 0-9 which has a total of 10 places;
print ("Welcome to : mainLibray 1.0");
print ("");
print ("This program will display all the data in 'names' array:");
print ("");
print ("");
for (int id = 0; id < 10; id++)
{
names[id] = id * 2 + 65;
}
for (int id = 0; id < 10; id++)
{
cout << "id : " << id << " = " << names[id] << "\n";
// cout << id << "\n";
}
int cnt = 1.1;
cout << cnt << endl;
// int cnt = 1;
printLine("My ");printLine("name ");printLine("is ");printLine("Dusty!");cout << endl;//printLine(cnt);
print(200303.112);
int a = 1;
int b = 2;
printLine("a = ");printLine(a);printLine(", b = ");print(b);
variableSwap(a,b);
printLine("a = ");printLine(a);printLine(", b = ");print(b);
double x = 1.1112;
double y = 2.2223;
printLine("x = ");printLine(x);printLine(", y = ");print(y);
variableSwap(x,y);
printLine("x = ");printLine(x);printLine(", y = ");print(y);
string n1 = "Polar Bear";
string n2 = "White Eagle";
printLine("n1 = ");printLine(n1);printLine(", n2 = ");print(n2);
variableSwap(n1,n2);
printLine("n1 = ");printLine(n1);printLine(", n2 = ");print(n2);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire