| | |
String issue
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Sep 2009
Posts: 31
Reputation:
Solved Threads: 0
This program collects 3 numbers from the user and then simple adds the total and spits out a response. problem is the final output is blank, it just says 'The total is: '_____ but nothing there. Whats wrong??
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int num[3]; for(int x=0; x<3; x++) { cout << "Enter a number: "; cin >> num[x]; } int sum=0; int x=0; for(int x=0; x<3; x++); { x=x+sum; cout << "The total is: "; cin >> x; } return 0; }
•
•
Join Date: Sep 2009
Posts: 31
Reputation:
Solved Threads: 0
0
#3 Oct 24th, 2009
thanks, i feel kinda dumb putting x as cin i changed that to
but the total just comes out as zero.
C++ Syntax (Toggle Plain Text)
cout << "The total is: " << x << endl;
but the total just comes out as zero.
•
•
Join Date: Sep 2009
Posts: 19
Reputation:
Solved Threads: 5
1
#4 Oct 24th, 2009
•
•
•
•
C++ Syntax (Toggle Plain Text)
int sum=0; int x=0; for(int x=0; x<3; x++); { x=x+sum; cout << "The total is: "; cin >> x; } return 0; }
0
#5 Oct 24th, 2009
This is problematice :
change to :
C++ Syntax (Toggle Plain Text)
int sum = 0; int x=0; // you declared it inside the for loop below for(int x=0; x<3; x++); { x=x+sum; //what happened to num array? cout << "The total is: "; cin >> x; }
C++ Syntax (Toggle Plain Text)
int sum = 0; for(int x=0; x<3; x++); sum = sum + num[x]; cout << "The total is: " << x << endl;
Last edited by firstPerson; Oct 24th, 2009 at 10:45 pm.
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
•
•
Join Date: Sep 2009
Posts: 31
Reputation:
Solved Threads: 0
0
#6 Oct 24th, 2009
Okay I see the logic, but there is a building error: 'x' is undeclared identifier. Heres my updated code.
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; int _tmain(int argc, _TCHAR* argv[]) { int num[3]; for(int x=0; x<3; x++) { cout << "Enter a number: "; cin >> num[x]; } int sum = 0; for(int x=0; x<3; x++); sum = sum + num[x]; cout << "The total is: " << x << endl; return 0; }
1
#7 Oct 24th, 2009
declare x outside of the for loop. Usually works for some reason..
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
int num[3], x = 0;
for(x; x<3; x++)
{
cout << "Enter a number: ";
cin >> num[x];
}
int sum = 0;
for(int x=0; x<3; x++);
sum = sum + num[x];
cout << "The total is: " << x << endl;
return 0;
} Last edited by restrictment; Oct 24th, 2009 at 11:05 pm.
1
#9 Oct 24th, 2009
print out the sum, cout<<sum << endl;
1) Prove that the area of a circle is pi*r^2, where "r" is the radius of the circle. 2) Problem 2[b]solved by : jonsca
![]() |
Similar Threads
- Updated : Simple ASP.Net Login Page (ASP.NET)
- Byte to string issue (Java)
- connection string issue (ASP.NET)
- String Issue :( (C++)
- Remote Database server error. (C#)
- help with polymorphism and inheritance...getting null values (Java)
Other Threads in the C++ Forum
- Previous Thread: Need Ideas for Project
- Next Thread: help me to solve this
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment based beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






