why isn't my program running?

Hi, well I'm doing this assignment where I have ask the user to input his/her name and display the name vertically(sorry I had reversed, it's vertically). esample:

if the user's name is blad and
if 2 is pressed by user, the output will be:
b
l
a
d

As far as I know everything is right, but I can't get the program to run. Can anyone tell me why please.

#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void printVertically(string name, int i);



int main() {
int i;
int j;
int option;

string name;
cin>>name;
cin>>option;

switch(option){
case 1:
void printVertically(string name, int i);
break;
default:
cout<<"hjgd";
}







cin.ignore(200, '\n');
int halt;
cin>>halt;

return 0;
}




void printVertically(string name, int i){
for(int i=0;i<name.size;i++)



cout<<name.substr(i,1)<<endl;
}



.
Last edited on
for(int i=0;i<name.size;i++)

Here it should be name.length()
Dear Rey,

Your question is unclear. Please clarify the following:
1. Do you want to print the word in reverse or vertically?
2. Do you want that done when the user enters 1 or 2?

Away from that you need to answer and correct the following:
1. Why are you including <fstream>? I can't see you using any file streaming and you don't need to for this assignmnet.
2. In your switch block there is this wrong line:

void printVertically(string name, int i);

You need to remove the void word to call the function. You can't redeclare the function when you call it. The compiler won't allow this illogical behavior. You also need to remove the word string for the same reason. You also need to remove that int i because you are not using any i from outside the function. That means that you need to have the following as a function prototype:

void printVertically(string name);

3. Why do you have the following varaibles in the main program? Remove these:

1
2
int i;
int j;



Oh, regarding the length() vs size() thing: size() is an alias for length(). They both do the same thing. Just make sure that you use it as a method, not a data member. That means rewriting that for loop in your printVertically function definition as:

for (int i = 0; i < name.size(); i++)
i'm so sorry. ShantDashjian you are right. I want ti print the name vertically. Thanks to everyone that has helped. I really appreciate that.
once again. thanks to everyone that helped.
Topic archived. No new replies allowed.