Ik ben nu bezig met C++ leren uit een boek (Aan de slag met C++) en ben nu bij een opgave waar je een soort van pyramide moet maken met behulp van geneste for-statements. Dit is wat ik er van gemaakt heb, en het werkt:
[cpp]
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int Space=8;
int Stars=1;
for(int TopCol=1; TopCol<=4; TopCol++)
{
for(int TopSpaceRow=1; TopSpaceRow<=Space; TopSpaceRow++)
{
cout << setw(Space);
}
Space--;
for(int TopStarRow=1; TopStarRow<=Stars; TopStarRow++)
{
cout << "*";
}
Stars+=2;
cout << endl;
}
Space=3;
Stars=10;
for(int BottomCol=1; BottomCol<=3; BottomCol++)
{
for(int BottomSpaceRow=1; BottomSpaceRow<=Space; BottomSpaceRow++)
{
cout << setw(Space);
}
Space--;
for(int BottomStarRow=1; BottomStarRow<=Stars; BottomStarRow++)
{
cout << "*";
}
Stars+=2;
cout << endl;
}
cin.get();
return(0);
}
[/cpp]
Ik vraag me alleen af of dit ook de bedoeling was, aangezien de code best lang is voor zo'n simpele opdracht. Ik kan het verder niet controlleren, ben de cd kwijt :/
[cpp]
#include "stdafx.h"
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int Space=8;
int Stars=1;
for(int TopCol=1; TopCol<=4; TopCol++)
{
for(int TopSpaceRow=1; TopSpaceRow<=Space; TopSpaceRow++)
{
cout << setw(Space);
}
Space--;
for(int TopStarRow=1; TopStarRow<=Stars; TopStarRow++)
{
cout << "*";
}
Stars+=2;
cout << endl;
}
Space=3;
Stars=10;
for(int BottomCol=1; BottomCol<=3; BottomCol++)
{
for(int BottomSpaceRow=1; BottomSpaceRow<=Space; BottomSpaceRow++)
{
cout << setw(Space);
}
Space--;
for(int BottomStarRow=1; BottomStarRow<=Stars; BottomStarRow++)
{
cout << "*";
}
Stars+=2;
cout << endl;
}
cin.get();
return(0);
}
[/cpp]
Ik vraag me alleen af of dit ook de bedoeling was, aangezien de code best lang is voor zo'n simpele opdracht. Ik kan het verder niet controlleren, ben de cd kwijt :/
Laatst bewerkt: