Im a newbie. And i want to know how can i add up the sum of array using a for loop and stop until a number.
E.g. i want to add up these counter until a number, e.g. 8. The total of these counter let say 15. How can i use a loop to add them up one by one and break it once >=8 is happened. please helpppppp.
int arry[10]{1,2,3,4,5,6,8,7,12,43};
int sum=0, index =0;
while(index < 10)
{
if(arry[index] >= 8)
break;
sum += arry[i];
++index;
}
std::cout<<""sum is: "<<sum;
for (int i=0; i<27; i++) //this loop is correct
{
counter[i]+=counter[i];///this is the same as arry[i]+=arry[i] or arry[i] = arry[i]*2; i dont know if this is what you want.
///did you intend to do smthng like sum += arry[i]; not sure/
if (counter[i]>=8)/// if you don't want counter[i] be included in the summation move this line to after the opening brace '{'.
break;
}
can you post you current working code, i'll try to help
@Yolanda
OMGG THANK YOU SO MUCH FOR DOING THISSSS !!
Here's my program. I can't thank you enough!!!
i thought that counter[i]+=counter[i] is a way of adding counter[1]+....+counter[26], is it wrong?
#include <iostream>
using namespace std;
int main(){
char msg[50];
int counter[27];
for (int i=0; i<50; i++){
msg[i]='\0';
}
cin.getline(msg,50);
for (int j=0; j<28; j++){
counter[j]=0;
}
for (int k=0; k<50; k++){
if (msg[k]>='A' && msg[k]<='Z')
msg[k]+='a'-'A';
if (msg[k]>='a' && msg[k]<='z'){
counter[int(msg[k])-96]++;
}
}
Here i want to add that part. Cuz my Question actually requires me to find the middle alphabet among a message input. The input will be according to alphabetical order, e.g. abeefgiiiimnopq by the formula N/2 +1. So if i input let say 15 alphabet, the middle one is 8. i.e. letter i. My aim is to find the letter just at the point >or=8.
//So if i input let say 15 alphabet, the middle one is 8.
this could be way easy...
but have tried reading your code \nd the is something m no getting,,, if you could post the question atleast i could be of more help than i can offer now from your comment.