#include<iostream> #include<iomanip> #include<cmath> using namespace std; int main(){ int a1,d,n,sum; char opt; cout<<"press 'e' for exit and 'c' for continue:"<<endl; cin>>opt; if(opt !='e' || opt != 'c' ){cout<<"invalid option: "<<endl; } else{ while(opt != 'e' && opt == 'c'){ cout<<"enter the starting number:"<<endl; cin>>a1; cout<<"enter the common difference:"<<endl; cin>>d; cout<<"enter the number of terms in the series:"<<endl; cin>>n; sum = (n*2*a1+n*d*(n-1))/2; cout<<sum<<endl; } } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter