473,385 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

programming problem

12
Hello everybody i need help with a problem please!!!
I am new to this and just trying to figure my Homework out....
Ok here it comes:

Write a program that asks the user to enter an integer between 1 and 10, sums the squares of the integers from 1 to the number entered, and display the sum. Thus, if the user enters 5, the program should display the following:

The sum of the squares of the integers from 1 to 5 is 55.


I am sure for you guys it is not an issue i am just starting my c++ class .....

please help me and give me some hints

Thx

Markus
Jan 31 '07 #1
9 1841
RedSon
5,000 Expert 4TB
Steps:

1. Ask the user for input between 1 and 10.
2. Square each number from 1 to inputted number and add it to a holding variable.
3. Display the sum.

Which part are you having problems with?
Jan 31 '07 #2
beck322
12
Steps:

1. Ask the user for input between 1 and 10.
2. Square each number from 1 to inputted number and add it to a holding variable.
3. Display the sum.

Which part are you having problems with?
Ok i got that but i am not familiar with all the vocabulary yet
that is my problem:
1. cout<<" Enter integer between 1 and 10:"<< endl;
cin >>integer>>;

please be patient with me i am new to this
Jan 31 '07 #3
RedSon
5,000 Expert 4TB
Ok i got that but i am not familiar with all the vocabulary yet
that is my problem:
1. cout<<" Enter integer between 1 and 10:"<< endl;
cin >>integer>>;

please be patient with me i am new to this
You are on the right track: (I fixed an error in your code)

Expand|Select|Wrap|Line Numbers
  1. cout<<" Enter integer between 1 and 10:"<< endl;
  2.     cin >>integer;
Keep going!
Jan 31 '07 #4
beck322
12
You are on the right track: (I fixed an error in your code)

Expand|Select|Wrap|Line Numbers
  1. cout<<" Enter integer between 1 and 10:"<< endl;
  2.     cin >>integer;
Keep going!
like that?
int main()
{
int i;

cout<< endl;
cout<<" Enter integer between 1 and 10 : "<< endl;
cin>>i

return 0;
}

and how do i square all the integers?

english is my second language too i am an international student from germany...
Jan 31 '07 #5
beck322
12
like that?
int main()
{
int i;

cout<< endl;
cout<<" Enter integer between 1 and 10 : "<< endl;
cin>>i

return 0;
}

and how do i square all the integers?

english is my second language too i am an international student from germany...
ok i just forgot to put a semicolon after the i now it runs but i dont know how to
square the inputs
Jan 31 '07 #6
Ganon11
3,652 Expert 2GB
In order to get i squared, you can use i*i.

The best way to calculate this value would be to use a for... loop, like so:

Expand|Select|Wrap|Line Numbers
  1. int sum = 0;
  2. for (int j = 1; j <= i; j++) { // i is the user-defined variable
  3.    //Calculation to add i*i to sum here
  4. }
Feb 1 '07 #7
beck322
12
#include "stdafx.h"
#include <iostream>
using namespace std;


int main()
{
int total = 0,
i,
number;

cout<< " Give me a number between one and 10:";
cin>> number;
for( i= 1; i <=number; ++i)
{
total=total+i*i;

}

cout << "The sum of squares of the integers from 1 to " << number <<"is :"<< total<< endl;


return 0;
}

I figured it out thank you!!!!!!
Feb 2 '07 #8
beck322
12
#include "stdafx.h"
#include <iostream>
using namespace std;


int main()// While loop same Exercise
{
int count=1,
number,
total=0;

cout<< " Give me a number between one and 10:";
cin>> number;
cout<< endl;
while(count <= number)

{
total +=count * count;
++count;

}

cout << "The sum of squares of the integers from 1 to " << number <<"is :"<< total<< endl;


return 0;
}

Or like that!!!!!
Feb 2 '07 #9
Roonie
99
good!

do you need to perform checks on your input data? if so that will be another few steps . . . for instance, do you need to check to make sure that the input is not greater than 10?

(and your english is very good.)
Mar 22 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

65
by: Roger Smythe | last post by:
A means for the progressive decomposition a problem space into increasingly simpler component parts such that these component parts represent higher levels of conceptual abstraction, and are...
3
by: user | last post by:
Hi all, At the outset, I regret having to post this slightly OT post here. However, I strongly feel that people in this group would be the best to advise me on my predicament. I am working as...
134
by: evolnet.regular | last post by:
I've been utilising C for lots of small and a few medium-sized personal projects over the course of the past decade, and I've realised lately just how little progress it's made since then. I've...
42
by: Kevin Spencer | last post by:
Is it just me, or am I really observing a trend away from analysis and probem-solving amongst programmers? Let me be more specific: It seems that every day, in greater numbers, people are coming...
6
by: bambooforest | last post by:
Hi all, I'm from a Linguistics background and am new(er) to programming. Could someone recommend a book or resource that teaches programming aspects with Python? Python I hear is a very...
7
by: Michael | last post by:
Hey, I'm, I guess, an itermediate programmer and I have a question about learning any programming language. I understand that as a programmer you're going to probably constantly be re-writing code...
10
by: stylecomputers | last post by:
Hey guys, I am absolutely new to Linux programming, with no w######s programming experience except a small amount of C++ console apps. Reasonably new to Linux, BSD etc, got good sound networking...
6
by: arnuld | last post by:
hai all, 1st of all this post is not about C++, it is about general programming, problems i am facing in learning the concepts & reflects my experience with C and C++ . i know about functions,...
111
by: Enteng | last post by:
Hi I'm thinking about learning C as my first programming language. Would you recommend it? Also how do you suggest that I learn it?What books/tutorials should I read for someone like me? Thanks...
17
Banfa
by: Banfa | last post by:
I felt that this was a good point to start a tutorial on C/C++ programming because clearly we need to have some idea of what we are trying to achieve before we start out. I recently found this...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.