| | |
Help Please New to C++
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Feb 2008
Posts: 69
Reputation:
Solved Threads: 0
Hello,
I am trying to create a program that asks a user to input a integer. That integer will dispaly "*" (i.e. enter 4 diplay - ****)
This is what I came up with so far to no luck!
I am trying to create a program that asks a user to input a integer. That integer will dispaly "*" (i.e. enter 4 diplay - ****)
This is what I came up with so far to no luck!
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> using std::cout; using std::cin; using std::endl; int main() { int n; cout << "Please enter a integer "; cin >> n; for (int i = n; i <= 25; n++) { cout << "*" ; } cout << endl; return 0; }
Hey, looking at your program looks like you have a few simple errors, logic and otherwise.
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n;
cout << "Please enter a integer ";
cin >> n;
for (int i = n; i <= 25; n++)
{
cout << "*" ;
}
cout << endl;
return 0;
}
#include "stdafx.h"
should be
#include <stdafx.h>
except when I ran it through my compiler it had no idea what that was, so when I removed it, it didn't affect functionality, so I'm not familiar with that one.
in your for loop, try this:
for (int i = 1; i <= n; i++)
{
cout << "*" ;
}
the reason for this is that the way you had it set up is that it would always display 25-n "*"'s which as I gather is not what you want. you also had n incrementing instead of the looping variable which it should have been. Chances are your program just kept on spitting out "*"'s indefinitely since the for loop would never be satisfied.
With that code modified it compiled and ran fine for me, let me know if it works for you.
Hope it helps!
~J
#include "stdafx.h"
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int main()
{
int n;
cout << "Please enter a integer ";
cin >> n;
for (int i = n; i <= 25; n++)
{
cout << "*" ;
}
cout << endl;
return 0;
}
#include "stdafx.h"
should be
#include <stdafx.h>
except when I ran it through my compiler it had no idea what that was, so when I removed it, it didn't affect functionality, so I'm not familiar with that one.
in your for loop, try this:
for (int i = 1; i <= n; i++)
{
cout << "*" ;
}
the reason for this is that the way you had it set up is that it would always display 25-n "*"'s which as I gather is not what you want. you also had n incrementing instead of the looping variable which it should have been. Chances are your program just kept on spitting out "*"'s indefinitely since the for loop would never be satisfied.
With that code modified it compiled and ran fine for me, let me know if it works for you.
Hope it helps!
~J
Last edited by jesseb07; Feb 22nd, 2008 at 11:37 pm.
![]() |
Other Threads in the C++ Forum
- Previous Thread: Dynamic stack in c++
- Next Thread: progressBar
Views: 394 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph homeworkhelper iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number output parameter pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





