Originally Posted by
recklezz
Code:
#include<iostream>
using namespace std;
int main()
{
int num1,next_numbers,total;
cout<<"enter the number:\n";
cin>> num1;
cout<<"\nenter next number:\n";
cin>> next_numbers;
if(!(num1==0 || next_numbers==0)) //checks if the entered values are not zero
{
total=num1+next_numbers;
cout<<"sum is at:\n"<<total;
for(next_numbers;next_numbers!=0;) //asks the user continuous input until he enters zero
{
cout<<"\nenter next number:\n";
cin>>next_numbers;
total=total+next_numbers;
cout<<"sum is at:\n"<<total;
}
}
}
is this ok?
thanks matticus
Your formatting looks acceptable, one nit-pick though - you could have:
Code:
total = total + next + next_number
You are free to chose your formatting style - but most formatting styles will look good as long as your remain consistent - for instance 'clang-format' gives me:
Code:
#include <iostream>
using namespace std;
int main() {
int num1, next_numbers, total;
cout << "enter the number:\n";
cin >> num1;
cout << "\nenter next number:\n";
cin >> next_numbers;
if (!(num1 == 0 ||
next_numbers == 0)) // checks if the entered values are not zero
{
total = num1 + next_numbers;
cout << "sum is at:\n" << total;
for (next_numbers;
next_numbers !=
0;) // asks the user continuous input until he enters zero
{
cout << "\nenter next number:\n";
cin >> next_numbers;
total = total + next_numbers;
cout << "sum is at:\n" << total;
}
}
}
That is the coding style used in most google projects.