You are using a version without Ads of this website. Please, consider donating:

### How would you display dynamic variables in a cout statement?

I need to store and display the results of my for loop in my cout statements, how would I do this?

// Garbage Collection.
#include <iostream>
#include <cmath>

using namespace std;

int main(){
double reg, glass, met;
double total;
double reg_ratio, glass_ratio, met_ratio;

cout << "How much regular, glass, and metal garbage do you have?" << endl;
cin>> reg;
cin>> glass;
cin>> met;

total= met+glass+reg;

cout<< "The total number of bags is "<< total<< endl;

met_ratio= met/total;
reg_ratio= reg/total;
glass_ratio= glass/total;

cout<< "The metal ratio is "<< met_ratio<< endl;
cout<< "The glass ratio is "<< glass_ratio<< endl;
cout<< "The regular ratio is "<< reg_ratio<< endl;
if( met==reg==glass)
{
cout<< "All garbage amounts are the same."<< endl;
}
else if (reg> glass && met)
{
cout<< "Regular is the largest."<< endl;
}
else if (glass> met && reg)
{
cout<< "Glass is the largest."<< endl;
}
else if (met> glass && reg)
{
cout<< "Metal is the largest."<< endl;
}

for(; reg <= 50; reg += reg){
cout << "I can only accept of your " " regular bags of garbage. I'll leave the other " " behind."<< endl;
}
for(; met <= 20; met += met){
cout << "I can only accept " " of your " " metal bags of garbage. I'll leave the other " " behind."<< endl;
}
for(; glass <= 20; glass += glass){
cout << "I can only accept " " of your " " glass bags of garbage. I'll leave the other " " behind."<< endl;
}
return 0;
}

As Per my experience of programming you can't do that. For loops are repeaptition structures and they are not meant for the task you want to do with them.

Secondly , you have already included the cout in your for loop . This is the method you do this .

 [u][b]Remember: For Loops are repition structures ad only meant for rep
eti[/u]ton[/b]
Okay, makes sense, thanks for the help!
Topic archived. No new replies allowed.