I am trying to do simple MPI distribution of for-loop iterations to “Worker” cores. The “Workers” should do the job (take vector of size “nGenes” in format double, typically ~6 in size) and send back the result (one variable in format double). But, I have trouble even with the first step, passing messages from “Master” core (0) to “Worker” cores (1,2,…,nWorkers). The program goes through the send messages part, but it’s stacked in the receiving part where the line with MPI_Recv(…) is. I can't see what might be the problem. Please help.
#include <iostream>
#include <mpi.h>
#include <math.h>
#include <stdlib.h> /* srand, rand */
double fR(double a);
void Calculate_MPI_Division_of_Work_Per_Core_Master0AndSlaves(int Number_of_Tasks, int NumberOfProcessors, int* START_on_core, int* END_on_core);
int main(int argc, char* argv[])
{
int nIndividuals = 10;
int nGenes = 6;
double** DATA;
DATA = new double* [nIndividuals];
for (int ii=0; ii<nIndividuals; ii++)
{
DATA[ii] = new double [nGenes];
}
for (int ii=0; ii<nIndividuals; ii++)
{
for (int jj=0; jj<nGenes; jj++)
{
DATA[ii][jj] = ii+jj; // random intialization of the elements.
}
}
int MyRank, NumberOfProcessors;
MPI_Init(&argc, &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &MyRank);
MPI_Comm_size(MPI_COMM_WORLD, &NumberOfProcessors);
int NumberOfWorkers = NumberOfProcessors - 1;
int* Iteration_START_on_core;
int* Iteration_STOP_on_core;
Iteration_START_on_core = new int [NumberOfWorkers+1];
Iteration_STOP_on_core = new int [NumberOfWorkers+1];
Calculate_MPI_Division_of_Work_Per_Core_Master0AndSlaves(nIndividuals, NumberOfProcessors, Iteration_START_on_core, Iteration_STOP_on_core);
if (MyRank == 0)
{
std::cout << " ======================== " << std::endl;
std::cout << std::endl;
std::cout << "NumberOfProcessors=" << NumberOfProcessors << std::endl;
std::cout << "NumberOfWorkers= " << NumberOfWorkers << std::endl;
std::cout << "NumberOfTasks= " << nIndividuals << std::endl;
for (int ww=0; ww<=NumberOfWorkers; ww++)
{
std::cout << "(Core: " << ww << ") S:" << Iteration_START_on_core[ww] << " E:" << Iteration_STOP_on_core[ww] << " LoadOnCore: ";
if (ww==0)
{
std::cout << 0 ;
}
else
{
std::cout << Iteration_STOP_on_core[ww] - Iteration_START_on_core[ww] +1;
}
std::cout << std::endl;
}
std::cout << std::endl;
std::cout << " ======================== " << std::endl;
}/// End_If(MyRank==0)
if (MyRank == 0)
{
std::cout << "Start Sending...." << std::endl ;
double* sendbuff;
sendbuff = new double [nGenes];
for (int cc=1; cc<=NumberOfWorkers; cc++)
{
for (int jj=Iteration_START_on_core[cc]; jj<=Iteration_STOP_on_core[cc]; jj++)
{
for (int gg=0; gg<nGenes; gg++)
{
sendbuff[gg] = DATA[jj][gg];
}
std::cout << std::endl << "SEND to Core " << cc << ": Start=" << Iteration_START_on_core[cc] << ", End=" << Iteration_STOP_on_core[cc] << ". Taks#: " << jj << " -- DATA: ";
MPI_Send(&sendbuff, nGenes, MPI_DOUBLE, cc, 0, MPI_COMM_WORLD);
for (int mm=0; mm<nGenes; mm++)
{
std::cout << DATA[jj][mm] << " | ";
}
}
}
std::cout << std::endl;
delete[] sendbuff;
std::cout << std::endl << "Finish sending." << std::endl ;
}
else
{
std::cout << std::endl << "...Worker Cores..." << std::endl ;
for (int cc=1; cc<=NumberOfWorkers; cc++)
{
if (MyRank == cc)
{
MPI_Status status;
double* receivebuff;
receivebuff = new double [nGenes];
//std::cout << "Start Receiving on Core " << cc << ". FROM job: " << Iteration_START_on_core[cc] << " TO job: " << Iteration_STOP_on_core[cc] << "." << std::endl ;
for (int kk=Iteration_START_on_core[cc]; kk<=Iteration_STOP_on_core[cc]; kk++)
{
MPI_Recv(&receivebuff, nGenes, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
std::cout << std::endl << "RECEIVE on Core: " << cc << ". From Core " << 0 << ": Start=" << Iteration_START_on_core[cc] << ", End=" << Iteration_STOP_on_core[cc] << ". Work on task: " << kk << ".";
std::cout << " | ";
for (int aa=0; aa<nGenes; aa++)
{
std::cout << receivebuff[aa] << " | ";
}
std::cout << std::endl;
}
delete [] receivebuff;
std::cout << std::endl << "Finish receiving on core " << cc << "." << std::endl ;
}
}
}
for (int ii=1; ii<nIndividuals; ii++)
{
delete[] DATA[ii];
}
delete[] DATA;
if (MyRank==0) std::cout << std::endl << "Prepare to MPI_Finalize ... " << std::endl ;
MPI_Finalize();
if (MyRank==0) std::cout << std::endl << "... Completed MPI_Finalize. " << std::endl ;
///######################################################################################################
return 0;
} /// END MAIN PROGRAM
///===========================================================================================================================
///
/// Function: MPI Division of Work per Core.
void Calculate_MPI_Division_of_Work_Per_Core_Master0AndSlaves(int Number_of_Tasks, int NumberOfProcessors, int* START_on_core, int* END_on_core)
{
int NuberOfWorkers = NumberOfProcessors-1;
int integer_Num_Tasks_Per_Worker = floor(Number_of_Tasks/NuberOfWorkers);
int reminder_Num_Taska_Per_Worker = Number_of_Tasks - integer_Num_Tasks_Per_Worker*NuberOfWorkers;
START_on_core[0] = -1;
END_on_core[0] = -1;
//std::cout << std::endl << "F: integer_Num_Tasks_Per_Worker = " << integer_Num_Tasks_Per_Worker << std::endl;
//std::cout << "F: reminder_Num_Taska_Per_Worker = " << reminder_Num_Taska_Per_Worker << std::endl;
if (reminder_Num_Taska_Per_Worker==0)
{
START_on_core[1] = 0;
END_on_core[1] = START_on_core[1] + integer_Num_Tasks_Per_Worker - 1;
for (int iProcess=2; iProcess<NumberOfProcessors; iProcess++)
{
START_on_core[iProcess] = START_on_core[iProcess-1] + integer_Num_Tasks_Per_Worker;
END_on_core[iProcess] = END_on_core[iProcess-1] + integer_Num_Tasks_Per_Worker;
}
}
else
{
START_on_core[1] = 0;
END_on_core[1] = START_on_core[1] + integer_Num_Tasks_Per_Worker - 1 + 1;
for (int iProcess=2; iProcess<reminder_Num_Taska_Per_Worker+1; iProcess++)
{
START_on_core[iProcess] = START_on_core[iProcess-1] + integer_Num_Tasks_Per_Worker+1;
END_on_core[iProcess] = END_on_core[iProcess-1] + integer_Num_Tasks_Per_Worker+1;
}
for (int iProcess=reminder_Num_Taska_Per_Worker+1; iProcess<NumberOfProcessors; iProcess++)
{
START_on_core[iProcess] = END_on_core[iProcess-1] +1;
END_on_core[iProcess] = START_on_core[iProcess] +integer_Num_Tasks_Per_Worker-1;
}
}
//
}
The root cause is you are not using send and receive buffers correctly.
sendbuff and receivebuff are pointers, so use them directly instead of their address.
MPI_Send(&sendbuff, nGenes, MPI_DOUBLE, cc, 0, MPI_COMM_WORLD);
MPI_Recv(&receivebuff, nGenes, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);
must be replaced with
MPI_Send(sendbuff, nGenes, MPI_DOUBLE, cc, 0, MPI_COMM_WORLD);
MPI_Recv(receivebuff, nGenes, MPI_DOUBLE, 0, 0, MPI_COMM_WORLD,MPI_STATUS_IGNORE);
As a side note, you do not need to use an intermediate buffer to send data, and you can simply
MPI_Send(DATA[jj], nGenes, MPI_DOUBLE, cc, 0, MPI_COMM_WORLD);
Also, there is no need for an outermost loop in the receive part
for (int cc=1; cc<=NumberOfWorkers; cc++)
if (MyRank == cc)
could be simply be replaced with
cc = MyRank
Last but not least, you can learn about MPI_Scatterv() or even MPI_Scatter() and inter-communicator, it is likely the best fit for what you are trying to achieve.
Related
I'm having some trouble on my code if yourcurrency is larger than convert the convert will choose the 2 instead of 1
can't figure it out what's wrong with my code i've tried on different compiler I think the issue is the code itself can you help me guys?
#include <iostream>
#include <string>
using namespace std;
int picked[5] = {0,0,0,0,0};
int main(){
string currentvalue[5][5] = {{"1","0.01818484","0.015423716","2.4462308","0.019060361"},{"55.012111","1","0.84815483","134.47933","1.0482778"},{"64.90818","1.1789799","1","158.58285","1.2359668"},{"0.40901121","0.0074303636","0.0063022858","1","0.0077907482"},{"52.511804","0.95391572","0.80907737","128.35738","1"}};
string currency[5] = {"Philippine Peso","euro","pounds","yen","usd"};
int yourcurrency;
int convert;
int timesToRun = 5;
int number = 1;
system("COLOR 0a");
cout << "Choose your currency \n" << endl;
for (int counter = 0 ; counter < timesToRun; counter++)
{
cout << number;
cout << "." + currency[counter] << endl;
number++;
}
cout << "\nOption: ";
cin >> yourcurrency;
system("CLS");
yourcurrency = yourcurrency - 1;
picked[yourcurrency] = 1;
cout << "Select your currency you want to convert into \n" << endl;
number = 1;
for (int counter = 0; counter < timesToRun; counter++)
{
if (picked[counter] != 1){
cout << number;
cout << "." + currency[counter] << endl;
number++;
}
}
cout << "\nOption: ";
cin >> convert;
system("CLS");
cout << currency[yourcurrency]+ " - " + currency[convert];
cout << " [" + currentvalue[yourcurrency][convert] + "] " << endl;
cout << "Amount: ";
int cash;
cin >> cash;
double value = stof(currentvalue[yourcurrency][convert]);
double total = cash * value;
cout << currency[convert]<< ": " << total;
}
I usually return an object of std::vector or std::map as an incoming reference paremeter(as funcVec2 and funcMap2 below). But it is a bit inconvenient when writing codes. So I think if I can use return value under c++11(as funcVec1 and funcMap1 below) because it will call move constructor but not copy constructor, so it maybe still spend only one construct time and no deconstruct as the form of incoming reference paremeter.
But I write the codes below to verify it and it turns out that funcVec1 and funcMap1 takes more times then funcVec2 and funcMap2. So I am confused now why funcVec1 and funcMap1 takes so long?
#include <iostream>
#include <vector>
#include <map>
#include <chrono>
using namespace std;
vector<int> funcVec1() {
vector<int >vec;
for (int i = 0; i < 10; ++i) {
vec.push_back(i);
}
return vec;
}
void funcVec2(vector<int>&vec) {
for (int i = 0; i < 10; ++i) {
vec.push_back(i);
}
return;
}
map<int, int> funcMap1() {
map<int, int>tmpMap;
for (int i = 0; i < 10; ++i) {
tmpMap[i] = i;
}
return tmpMap;
}
void funcMap2(map<int, int>&tmpMap) {
for (int i = 0; i < 10; ++i) {
tmpMap[i] = i;
}
}
int main()
{
using namespace std::chrono;
system_clock::time_point t1 = system_clock::now();
for (int i = 0; i < 100000; ++i) {
vector<int> vec1 = funcVec1();
}
auto t2 = std::chrono::system_clock::now();
cout << "return vec takes " << (t2 - t1).count() << " tick count" << endl;
cout << duration_cast<milliseconds>(t2 - t1).count() << " milliseconds" << endl;
cout << " --------------------------------" << endl;
vector<int> vec2;
for (int i = 0; i < 100000; ++i) {
funcVec2(vec2);
}
auto t3 = system_clock::now();
cout << "reference vec takes " << (t3 - t2).count() << " tick count" << endl;
cout << duration_cast<milliseconds>(t3 - t2).count() << " milliseconds" << endl;
cout << " --------------------------------" << endl;
for (int i = 0; i < 100000; ++i) {
map<int, int> tmpMap1 = funcMap1();
}
auto t4 = system_clock::now();
cout << "return map takes " << (t4 - t3).count() << " tick count" << endl;
cout << duration_cast<milliseconds>(t4 - t3).count() << " milliseconds" << endl;
cout << " --------------------------------" << endl;
map<int, int>tmpMap2;
for (int i = 0; i < 100000; ++i) {
funcMap2(tmpMap2);
}
auto t5 = system_clock::now();
cout << "reference map takes " << (t5 - t4).count() << " tick count" << endl;
cout << duration_cast<milliseconds>(t5 - t4).count() << " milliseconds" << endl;
cout << " --------------------------------" << endl;
return 0;
}
you are not only meassuring the time for your operations, you also include the printouts. this is suboptimal.
you should measure performance in release mode. be aware that you are not doing anything usefull with your objects and the optimizer may throw away most of your code you wanted to measure.
the comparisons are not "fair". for example in your map1 case you are constructing an empty map, fill it (memory allocations happen here) and then you throw it away. in the map2 case you are reusing the identical map object over and over again. you are not allocating memory over and over again.
My program can't read all of the data from my MarvelIn.txt file.
It reads about 29 spaces in, and MarvelIn.txt contains only 9 entries, then I get a runtime error.
I think I have all the syntax right, however this is the only error I have. It will not output to the output file "MarvelOut.txt".
Here is the code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
#include <stdio.h>
using namespace std;
struct sstruct
{
string first, last;
string department;
int salary;
};
void init2(sstruct s[50])
{
int maxarray = 50;
sstruct init = { "Darth", "Vader", "None", 0 };
for (int i = 0; i < maxarray; i++) {
s[i] = init;
cout << "init: " <<s[i].first<<endl;
}
}
void read(sstruct s[50], int &nums)
{
int maxarray = 50;
ifstream inf("MarvelIn.txt");
int i = 0;
while (!inf.eof())
{
inf >> s[i].first >> s[i].last >> s[i].department >> s[i].salary;
cout << "read: "<<s[i].first<<s[i].last << s[i].department <<
s[i].salary << endl;
i++;
}
nums = i;
}
void avg(sstruct s[50], int &nums, double &average2)
{
int maxarray = 50;
int i;
for (i = 0; i < nums; i++)
average2 += s[i].salary;
average2 /= nums;
}
void print(sstruct s[50], int nums, double &average2)
{
int maxarray = 50;
ofstream outf("MarvelOut.txt");
int i = 0;
string temp;
outf << "the number of professors is: " << nums << endl;
cout << "the number of professors is: " << nums << endl;
outf << endl << "The average salary of the professors is: " << average2 << endl;
outf << "Advisor " << "Major " << " Department " << "Salary " << endl;
for (i = 0; i < nums; i++)
{
temp= s[i].last + "," + s[i].first;
cout << "last, first " << temp << endl;
outf << left << setw(20) << temp << right << setw(5)<< s[i].department << setw(5) << s[i].salary << setw(8) << endl;
}
outf << endl << endl;
}
void swap(sstruct &a, sstruct &b)
{
sstruct temp;
temp=a;
a=b;
b=temp;
}
void bubbleSort(sstruct s[50], int &nums)
{
int maxarray = 50;
int i, j;
bool swapped;
for (i = 0; i < nums - 1; i++)
{
swapped = false;
for (j = 0; j < nums - i - 1; j++)
{
if (s[j].department > s[j + 1].department)
{
swap(s[j], s[j+1]);
swapped = true;
}
}
// IF no two elements were swapped by inner loop, then break
if (swapped == false)
break;
}
}
int main() {
int nums=0;
double average3=0.0;
const int maxarray = 50;
sstruct s[maxarray];
init2(s);
print(s, nums, average3);
read(s, nums);
cout << "numsfirst: " << nums << endl;
avg(s, nums, average3);
cout << "nums" << nums << endl;
bubbleSort(s,nums);
print(s, nums, average3);
system("pause");
return 0;
}
I'm trying to write a script which could inline replace a printf statement with the cout statement. It could be either in sed or awk.
For example, if printf statement is
printf("int=%d, str=%s", i, s) ;
Then it should be replaced with :
cout << "int=" << i << ", str=" << s;
printf statement could have any no. of arguments. Accordingly, cout statement should be generated and replaced inline.
Other such examples could be:
printf("Statement2: %d %d %s %f", i, j, s ,f);
printf("statement3: %d %f",
i,
f);
CString failedMsg;
failedMsg.Format(_T("FAILED Triggered=%d expected=%d in %s"),
(int)i,
(int)j,
static_cast<LPCTSTR>(__TFUNCTION__));
Output:
cout << "Statement2: " << i << " " << j << " " << s << " " << f;
cout << "statement3: " << i << " " << f;
std::stringstream failedMsg;
failedMsg << "FAILED Triggered=" << (int)i
<< " expected=" << (int)i
<< " in " << __TFUNCTION__;
Yes, I'm new to StackOverflow. I'll learn the way how it works and how to ask for help. But for right now I'll just request for your gracious support to solve this.
Thanks.
───▄██▄─██▄───▄
─▄██████████▄███▄
─▌████████████▌
▐▐█░█▌░▀████▀░░
░▐▄▐▄░░░▐▄▐▄░░░░
using Perl if your printf function is on a single line not separate line; otherwise I think you cannot
for something like:
printf("int=%d, str=%s", i, s) ;
std::cout << "one" << '\n'; // just for sure
printf("one=%d, two=%d, three=%d, four=%d, five=%d", a, b , c, d , e);
for( int i = 0; i < 10; ++i ){
std::cout << i << '\n';
}
you can:
perl -ne '$T=0;/printf/ && s/printf|[ ",;()]+|%[a-z]/ /g && (#A=split) && ($T=1);if($T){$s=($#A+1)/2;$n=0;print "std::cout << ";print "\"$A[$n] \" << $A[$n+++$s] << " for 1..$s;print q("\n":),"\n";}else{print}' file
the output:
std::cout << "int= " << i << "str= " << s << "\n":
std::cout << "one" << '\n'; // just for sure
std::cout << "one= " << a << "two= " << b << "three= " << c << "four= " << d << "five= " << e << "\n":
for( int i = 0; i < 10; ++i ){
std::cout << i << '\n';
}
For something like:
printf("Statement2: %d %d %s %f", i, j, s ,f);
std::cout << "one" << '\n'; // just for sure
printf("Statement2: %d %d %s %f", i, j, s ,f);
for( int i = 0; i < 10; ++i ){
std::cout << i << '\n';
}
You can use: ( as script.sh )
perl -ne '$T=0;/printf/ && s/printf|[ ",;()]+|%[a-z]/ /g && (#A=split) && ($T=1);if($T){$n=0;print "std::cout << \"$A[0] \" << ";print " $A[++$n] <<" for 1..$#A-1;print q( "\n"),"\n"; }else{print}' file
the output:
std::cout << "Statement2: " << i << j << s << "\n"
std::cout << "one" << '\n'; // just for sure
std::cout << "Statement2: " << i << j << s << "\n"
for( int i = 0; i < 10; ++i ){
std::cout << i << '\n';
}
Main Program
#include <iostream>
#include <iomanip>
#include "pizza.h"
using namespace std;
int main() {
menuItem item;
menu:
item.getMenu();//Menu Prompt
cout << "\nI would like number: " << flush;
int menuChoice;
cin >> menuChoice;
while (menuChoice < 1 || menuChoice > 3) {
cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
}
if (menuChoice == 1) {
item.getPizza();
}
if (menuChoice == 2) {
item.getSandwhich();
}
if (menuChoice == 3) {
item.getSide();
}
int ready4checkout;
cout << "\n\n~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~*~" << endl;
cout << "\nAre you ready to checkout?\n" << endl;
cout << "checkout = 1\nAdd to the order = 2" << endl;
cout << "\nI would like to:" << flush;
cin >> ready4checkout;
if (ready4checkout == 1) {
item.addcheckout();
}
if (ready4checkout == 2) {
goto menu;
}
cin.ignore();
cin.get();
}
Header File
#include<iostream>
#include <iomanip>
using namespace std;
class menuItem {
protected:
float smallPizza = 5.99;
float mediumPizza = 6.99;
float largePizza = 9.99;
float halfSandwhich = 6.00;
float wholeSandwhich = 8.00;
float bonelessWings = .70;
float breadStix = 4.99;
public:
float checkout;
float pizzaCheck;
float sandCheck;
float sideCheck;
menuItem item(float smallPizza, float mediumPizza, float largePizza, float halfSandwhich, float wholeSandwhich, float bonelessWings, float breadStix,float checkout);
string getMenu() {
string menu;
cout << "~*~*~*~*~*~*~*~ Welcome to Pizza Italiano! ~*~*~*~*~*~*~*~*~\n\n" << endl;
cout << "~~~~~~~~~~~~~~~~~ Main Menu ~~~~~~~~~~~~~~~~~~" << endl;
cout << "Enter the value of the food that you wish to devour:\n" << endl;
cout << "\n1.Pizza\n2.Sandwhich\n3.Appetizer" << endl;
return menu;
}
string getPizza() {
float pizzaCheck;
string pizza;
float pizzaSize;
pizza:
cout << " \n~~~~~~ How would you like your pizza made? ~~~~~~\n" << endl;
cout << " Size" << endl;
cout << "-----------" << endl;
cout << "1. Large $9.99 \n2. Medium $6.99 \n3. Small $5.99" << endl;
cout << "\nI would like the number: " << flush;
cin >> pizzaSize;
cin.ignore();
while (pizzaSize < 1 || pizzaSize > 3) {
cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
goto pizza;
}
if(pizzaSize == 1) {
cout << "\n****You have selected a Large pizza****" << endl;
pizzaCheck = pizzaSize;
pizzaCheck = largePizza + pizzaCheck;
} else if(pizzaSize == 2) {
cout << "\n****You have selected a Medium Pizza****" << endl;
pizzaCheck = pizzaSize;
pizzaCheck = mediumPizza + pizzaCheck;
} else {
cout << "\n****You have selected a Personal pizza****" << endl;
pizzaCheck = pizzaSize;
pizzaCheck = smallPizza + pizzaCheck;
}
cin.get();
return pizza;
}
string getSandwhich() {
string sandwhich;
float sandSize;
Sandwhich:
cout << "~~~~~~~~~~~~ What size would you like your sandwhich to be? ~~~~~~~~~~~~~~~\n\n" << endl;
cout << "1. Six inch $6.00\n2. Twelve inch $8.00" << endl;
cout << "I would like number:" << flush;
cin >> sandSize;
while (sandSize < 1 || sandSize > 2) {
cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
goto Sandwhich;
}
if (sandSize == 1) {
cout << "**** You have selected a six inch sub ****" << endl;
sandCheck = halfSandwhich + sandSize;
} else {
cout << "**** You have selected a 12 inch sub ****" << endl;
sandCheck = wholeSandwhich + sandSize;
}
return sandwhich;
}
string getSide() {
string Appetizer;
float side;
sides:
cout << "~~~~~~~~~~~~~~~ Which appetizer would you like? ~~~~~~~~~~~~~~~~~\n\n" << endl;
cout << "1. Boneless Wings .70\n2. BreadStix $4.99\n\n" << endl;
cout << "I would like the number:" << flush;
cin >> side;
while (side < 1 || side > 2) {
cout << "\nINVAILD INPUT:\nEnter a Value that corresponds with your menu choice" << endl;
goto sides;
}
if (side == 1) {
cout << "\n**** You have selected Boneless wings ****\n" << endl;
cout << "How many wings would you like?\n" << endl;
cout << "I would like this many wings:" << flush;
int wings;
cin >> wings;
cout << "\n**** You will recieve " << wings << " wings. ****" << endl;
side = sideCheck;
sideCheck = bonelessWings += sideCheck;
} else {
cout << "\n**** You have selected an order of breadstix ****" << endl;
side = sideCheck;
sideCheck = breadStix += sideCheck;
}
return Appetizer;
}
float addcheckout() {
checkout = pizzaCheck;
cout << "\nYour total is " << checkout << endl;
cout << "\nThank You for your purchase!";
return checkout;
}
};
At the end of the program, when it gives the checkout total, it gives a value something like -1.07374e.+008
I am still learning how to code, and I am stumped on this one. Any help would be much appreciated!
I think you shadow your member field pizzaCheck in your method getPizza, so that you actually don‘t write to the member field but to your local var declared at the first line of that method.
Try removing that local var. (I did not test it yet though)