Hi!
Actually, i'm too beginner to ask such a question, I just started C++ and I'm reading the whole Documentation part of this site!
But when I write programs, sometimes things doesn't work correctly!
For example the last program I was trying to write was:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
#include <iostream>
#include <string>
using namespace std;
int main()
{
char a,b,c; int d,e=0;string suffix;
cout<< "How many numbers you got for me to sum up?"<<endl;
cin>>a;
for (b=1;b<=a;b++)
{
c=b%10;
switch (c)
{
case 1:
suffix=("st");
break;
case 2:
suffix=("nd");
break;
case 3:
suffix=("rd");
default:
suffix=("th");
}
cout<<"Enter the "<<b<<suffix<<" number :"<<endl;
cin>>d;
e=d+e;
}
cout<<e;
}
|
As you see I wanted it to write down something like this:
1st, 2nd, 3rd, 4th, 5th, ... (I know it's not correct for 11, 12 and 13, but that doesn't matter) but it doesn't work! Instead of writing numbers, it draws some funny pics! (In VisualStudio>Win32ConsoleApplication>C++Class)
neither the whole program, nor the part bthat is supposed to write down 12t, 2nd & ...!
What is wrong?
Is it because i'm working with Visual Studio? (Win32ConsoleApplication)
Or is it something wrong with the code?
or ... ?