so alam mo function ng for loop and do while loop?Ganito lang format ng loop.
while (parameter)
{
code
}
do
{
code
} while(bool)
for(statements)
{
code
}
walang
for(statemetns)
{
code
} while(bool)
gets mo na?
so alam mo function ng for loop and do while loop?Ganito lang format ng loop.
while (parameter)
{
code
}
do
{
code
} while(bool)
for(statements)
{
code
}
walang
for(statemetns)
{
code
} while(bool)
gets mo na?
Ito try mo.Gawa mo ba yn boss or copy paste mo lng ?
May error kc. Btw ty![]()
#include <iostream>
using namespace std;
int main ()
{
int i = 0, sum = 0;
int input;
float ave;
while(true)
{
cout<< i+1<< ".Enter a Grade (Enter negative integer to stop): ";
cin>> input;
if(input < 0)
{
break;
}
i++;
sum += input;
cout << "Current Sum : " << sum << endl;
}
ave = sum /(i*1.0);
cout << " Average : " << ave <<endl;
return 0;
}
Same lang yang 3. Dependeso alam mo function ng for loop and do while loop?
so alam mo function ng for loop and do while loop?ryGanito lang format ng loop.
while (parameter)
{
code
}
do
{
code
} while(bool)
for(statements)
{
code
}
walang
for(statemetns)
{
code
} while(bool)
gets mo na?
Thanks bossIto try mo.
Code:#include <iostream> using namespace std; int main () { int i = 0, sum = 0; int input; float ave; while(true) { cout<< i+1<< ".Enter a Grade (Enter negative integer to stop): "; cin>> input; if(input > -1) { i++; sum += input; cout << "Current Sum : " << sum << endl; } else { break; } } ave = sum /(i*1.0); cout << " Average : " << ave <<endl; return 0; }

Same lang yang 3. Depende
Kung kailangang gawin muna tsaka icheck do-while.
for loop and while loop parehas lang.
Pero ang for loop more on increments.
Gawa mo ba yn boss or copy paste mo lng ?
May error kc. Btw ty![]()
Ano complicated dyan? Sobrang basic nga nyanmasyadong complicated para sa easy problem.
Mali kasi flow. Tinatawag mo yung Func1. Pero hindi nasasave yung value nung mga variable sa loob nung function na yun. Kung tatawagin ulit, magiinitialize ulit yung values ng mga yun. Na try mo ba yang code mo?A
Ano complicated dyan? Sobrang basic nga nyan
Gumawa lng ng other separate function para sa iloloop na code then call sa main func.
Oo naman nasasave values nyan, coded via dev c++ yn. Ivideo ko pa?Mali kasi flow. Tinatawag mo yung Func1. Pero hindi nasasave yung value nung mga variable sa loob nung function na yun. Kung tatawagin ulit, magiinitialize ulit yung values ng mga yun. Na try mo ba yang code mo?
Para maging tama code mo. Kailangan na declare din yung variables sa loob ng func1 mo as global variables.A
Ano complicated dyan? Sobrang basic nga nyan
Gumawa lng ng other separate function para sa iloloop na code then call sa main func.
Try mo icompile sa dev c++Para maging tama code mo. Kailangan na declare din yung variables sa loob ng func1 mo as global variables.
Teka open ko pc check koMali nga.. Haha!
View attachment 470948
Then mali ang compiler.
Then mali ang compiler.
Kung itatry mo yang code mo dito, incorrect pa rin.
You do not have permission to view the full content of this post. Log in or register now.
Kung sa dev c++ lang gagana code do you think tama yun?
And, the concept is the variables inside a function called are only temporary. after matapos yung task nun.
Yeah.I see. May point ka. Kung hindi gumagana sa current compiler nya. O diyan, he/she can place the local variables to global variables then compile. Easy.
#include <iostream>
using namespace std;
int main()
{
float input = 0, grades = 0;
int gradesCounter = 0;
cout<<"Enter Negative Grade To Stop"<<endl;
while(true)
{
cout<<"Enter Grade: ";
cin>>input;
if (input >= 0)
{
grades+=input;
gradesCounter++;
}
else { break; }
}
cout<<"Total Grade/s: "<<gradesCounter<<endl;
cout<<"Average: "<<(grades/gradesCounter);
return 0;
}
Ito try mo.
Code:#include <iostream> using namespace std; int main () { int i = 0, sum = 0; int input; float ave; while(true) { cout<< i+1<< ".Enter a Grade (Enter negative integer to stop): "; cin>> input; if(input < 0) { break; } i++; sum += input; cout << "Current Sum : " << sum << endl; } ave = sum /(i*1.0); cout << " Average : " << ave <<endl; return 0; }